https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103237
Bug ID: 103237 Summary: wrong code with -ftree-vectorize at -O1 on x86_64-linux-gnu Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: haoxintu at gmail dot com Target Milestone: --- Hi all. This seems a long latent bug existed after GCC-10.1. $cat small.c #include <stdint.h> #include <stdio.h> struct S0 { uint16_t a; }; union U1 { struct S0 b; }; int32_t g1[1] = {0}; uint32_t g2[][10][1] = { {}, {}, {}, {}, {}, {}, {{}, {}, {}, {}, {}, {}, {4294967295UL}}}; union U1 g3; static int32_t func_1() { int32_t *l_1 = &g1[0]; uint32_t l_2 ; for (g3.b.a = (27); (g3.b.a != 45); g3.b.a = g3.b.a + 9) { for (l_2 = 0; (l_2 <= 3); l_2 += 1) { uint32_t *l_3 = &g2[6][6][0]; *l_1 = *l_3 ^= ((0 == 0) << 0); } } return 0; } int main() { func_1(); for (int i = 0; i < 1; i++) printf("%d\n", g1[i]); return 0; } $gcc -O2 -ftree-vectorize small.c ; ./a.out -1 $gcc -O1 -ftree-vectorize small.c ; ./a.out 0 $gcc -O1 small.c ; ./a.out -1 $gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/home/haoxin/haoxin-data/compilers/gcc/build/libexec/gcc/x86_64-pc-linux-gnu/12.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with:../configure --prefix=/home/haoxin/haoxin-data/compilers/gcc/build/ --enable-bootstrap --enable-checking=release --enable-multilib --enable-languages=c,c++,lto --no-create --no-recursion Thread model: posix Supported LTO compression algorithms: zlib gcc version 12.0.0 20211114 (experimental) (GCC) Can also check here: https://godbolt.org/z/ncar1aWYM Thanks, Haoxin