https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128267
Bug ID: 128267
Summary: wrong code at -O2 with -march=x86-64-v4: a signed char
shift induction is 64 again instead of 0 after 256
iterations
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: kyuwoncho18 at gmail dot com
Target Milestone: ---
Target: x86_64-pc-linux-gnu
#include <stdio.h>
__attribute__((noipa)) void foo(signed char *a)
{
signed char b = 64;
for (unsigned i = 0; i < 257; ++i) {
a[i] = b;
b >>= 1;
}
}
int main(void)
{
signed char a[257];
foo(a);
printf("%d\n", a[256]);
return 0;
}
godbolt: https://godbolt.org/z/nPWKGWY8h
b is 0 from the eighth iteration on, so a[256] is 0 and the program must print
0, as it does at -O0, at -O2 -march=x86-64-v3 and with -O2 -march=x86-64-v4
-fno-tree-loop-vectorize. On an AVX-512 machine, -O2 -march=x86-64-v4 and -O3
-march=x86-64-v4 print 64.