[Bug rtl-optimization/85237] New: missed optimisation opportunity for large/negative shifts
vegard.nossum at oracle dot com
gcc-bugzilla@gcc.gnu.org
Thu Apr 5 17:21:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85237
Bug ID: 85237
Summary: missed optimisation opportunity for large/negative
shifts
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: vegard.nossum at oracle dot com
CC: segher at gcc dot gnu.org
Target Milestone: ---
Input:
int f(int x)
{
return 100 >> (10000 * (x == 1));
}
With -O3 I get:
f(int):
cmpl $1, %edi
movl $100, %edx
movl $0, %eax
cmovne %edx, %eax
ret
However, (x == 1) must always be 0, since the shift would be too large (and
cause UB) otherwise. Clang is able to see this and always outputs:
f(int): # @f(int)
movl $100, %eax
retq
I believe a similar example would be simply:
int f(int x)
{
return 100 >> (INT_MAX * x);
}
where again, the only valid (non-UB) value for x is 0.
More information about the Gcc-bugs
mailing list