https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128125
Bug ID: 128125
Summary: wrong code at -O1 with .CTZ of a signed int (-fgimple)
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: yuki.tanaka at defaultcase dot de
Target Milestone: ---
int __GIMPLE (ssa) __attribute__((noipa)) a(int x)
{
int _1;
__BB(2):
if (x_2(D) > 1)
goto __BB4;
else
goto __BB3;
__BB(3):
_1 = .CTZ (x_2(D));
return _1;
__BB(4):
return -1;
}
int main()
{
if (a(-8) != 3)
__builtin_abort();
return 0;
}
At -O{1,2,3,s} -fgimple this aborts with GCC 17, -O0 is fine. Also already
aborts at GCC 9.1.
Compiler Explorer, -O2 -fgimple:
GCC 17.0.0 (same with 9.1):
"a":
xor eax, eax
cmp edi, 1
setle al
sub eax, 1
ret