https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122213
Bug ID: 122213
Summary: {CEIL,ROUND}_DIV_EXPR produces wrong results when
constant operand is 2 or power of 2 with O2 flag
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: avinashd at gcc dot gnu.org
CC: jskumari at gcc dot gnu.org, meissner at gcc dot gnu.org,
rguenth at gcc dot gnu.org, segher at gcc dot gnu.org
Target Milestone: ---
Minimal repro
#include <stdio.h>
#define Y 8u
unsigned int __GIMPLE ceil_div_gimple (unsigned int a)
{
unsigned int D;
D = a __CEIL_DIV Y;
return D;
}
unsigned int ceil_div(unsigned int a)
{
unsigned int r = a % Y;
unsigned int q = a / Y;
if (r > 0 && (a ^ Y) >= 0)
q++;
return q;
}
int main ()
{
printf (ceil_div (19u) == ceil_div_gimple (19u) ? "PASS" : "FAIL");
}
compile this file in 2 ways
gcc -O0 -fgimple test.c && ./a.out
PASS
gcc -O2 -fgimple test.c && ./a.out
FAIL
