https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69342
Bug ID: 69342 Summary: wrong code at -O1, -O2, -O3 (NOT -Os) on x86-64-linux-gnu (in 32- and 64-bit modes) Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: chengniansun at gmail dot com Target Milestone: --- The following code is miscompiled by gcc trunk at -O1, -O2, -O3 (but not -Os) in 32-bit and 64-bit modes. $: gcc-trunk -v Using built-in specs. COLLECT_GCC=gcc-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-trunk/configure --prefix=/usr/local/gcc-trunk --enable-languages=c,c++ --disable-werror --enable-multilib Thread model: posix gcc version 6.0.0 20160117 (experimental) [trunk revision 232481] (GCC) $: $: gcc-trunk small.c -O1 ; ./a.out 1 $: gcc-trunk small.c -O2 ; ./a.out 1 $: gcc-trunk small.c -O3 ; ./a.out 1 $: gcc-trunk small.c -O1 -m32 ; ./a.out 1 $: gcc-trunk small.c -O2 -m32 ; ./a.out 1 $: gcc-trunk small.c -O3 -m32 ; ./a.out 1 $: gcc-trunk small.c -Os -m32 ; ./a.out 4 $: gcc-trunk small.c -Os -m64 ; ./a.out 4 $: gcc-trunk small.c -O0 ; ./a.out 4 $: $: cat small.c int printf(const char*, ...); static int a[40] = {7, 5, 3, 3, 0, 0, 3}; short b; int c = 5; int main() { b = 0; for (; b <= 3; b++) if (a[b + 6] ^ (0 || c)) ; else break; printf("%d\n", b); return 0; } $: