https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99079
Bug ID: 99079
Summary: Maybe a wrong code since r6-1462-g4ab1e111ef0669bb
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: marxin at gcc dot gnu.org
CC: rguenth at gcc dot gnu.org
Target Milestone: ---
Since the revision, we optimize the following in a different way:
$ cat x.cpp
unsigned long var = 31;
unsigned long arr;
static void test()
{
unsigned long s = 1 << var;
arr = 4897637220ULL % s;
}
int main()
{
test();
__builtin_printf ("arr: %ld\n", arr);
if (arr != 4897637220ULL)
__builtin_abort();
return 0;
}
$ g++ x.cpp && ./a.out
arr: 4897637220
$ g++ x.cpp && ./a.out
arr: 4897637220
Clang is fine with the test-case:
$ clang++ x.cpp -O3 && ./a.out
arr: 4897637220
and ICC as well.