https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126563
Bug ID: 126563
Summary: Wrong code with ifcombine and recognize_bits_test
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ktkachov at gcc dot gnu.org
Target Milestone: ---
/* ifcombine recognize_bits_test: after the operand swap the widening
sign-extends the AND-typed name into the mask type. */
__attribute__((noipa)) int f (long mm, int a, int b)
{
int m = (int) mm;
int y = a + b;
if ((m & y) == 0 && (y & 4) == 0)
return 1;
return 0;
}
__attribute__((noipa)) int ref (long mm, int a, int b)
{
volatile int m = (int) mm;
volatile int y = a + b;
volatile int t1 = (m & y) == 0;
if (!t1) return 0;
volatile int t2 = (y & 4) == 0;
if (!t2) return 0;
return 1;
}
int main (void)
{
long mm = 0x100000000L;
int bad = 0;
for (int a = -16; a <= 16; a++)
for (int b = -16; b <= 16; b++)
{
int got = f (mm, a, b), want = ref (mm, a, b);
if (got != want)
bad++;
}
if (bad) __builtin_abort ();
return 0;
}
aborts at -O2 on aarch64 and passes at -O0