https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122518
Bug ID: 122518
Summary: Canonicalize SUB (a, b) underflow checks to a < b
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: ubizjak at gmail dot com
Target Milestone: ---
The following testcase:
--cut here--
inline unsigned min (unsigned a, unsigned b)
{
return (a < b) ? a : b;
}
unsigned uminsub (unsigned a, unsigned b)
{
return min (a - b, a);
}
--cut here--
compiles with -O2 -m32 -march=i386 -mregparm=3 to:
uminsub:
movl %eax, %ecx
subl %edx, %eax
cmpl %eax, %ecx
jnb .L2
movl %ecx, %eax
.L2:
ret
SUB and CMP in the above testcase can be merged, because SUB (a, b) underflows
precisely when a < b. Convert (compare (minus (a b)) a) to (compare (a b))
to match *sub<mode>_3 pattern.