http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59058
Bug ID: 59058 Summary: wrong code at -O3 on x86_64-linux-gnu (affecting gcc 4.6 to trunk) Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: su at cs dot ucdavis.edu The current gcc trunk (as well as 4.6, 4.7, and 4.8) miscompiles the following code on x86_64-linux-gnu at -O3 in both 32-bit and 64-bit modes. It also affects gcc 4.6 and 4.7 at -O2, older versions of gcc, and on other platforms. For trunk and 4.8 (but not for 4.6 and 4.7 though), -fno-tree-vectorize makes the bug go away. Interestingly also, both the current clang and icc fail on this testcase too. $ gcc-trunk -v Using built-in specs. COLLECT_GCC=gcc-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror --enable-checking=release --with-gmp=/usr/local/gcc-trunk --with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk --with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk Thread model: posix gcc version 4.9.0 20131108 (experimental) [trunk revision 204593] (GCC) $ $ gcc-trunk -O2 small.c; a.out -1 $ gcc-trunk -O3 small.c; a.out 7 $ gcc-4.8.2 -O3 small.c; a.out 7 $ gcc-4.7.3 -O3 small.c; a.out 131071 $ gcc-4.7.3 -O2 small.c; a.out 131071 $ gcc-4.6.4 -O3 small.c; a.out 131071 $ gcc-4.6.4 -O2 small.c; a.out 131071 $ $ gcc-trunk -O3 -fno-tree-vectorize small.c; a.out -1 $ gcc-4.8.2 -O3 -fno-tree-vectorize small.c; a.out -1 $ gcc-4.7.3 -O3 -fno-tree-vectorize small.c; a.out 131071 $ gcc-4.6.4 -O3 -fno-tree-vectorize small.c; a.out 131071 $ $ clang-trunk -O3 small.c; a.out 0 $ icc -O3 small.c; a.out 1 $ -------------------------------------- int printf (const char *, ...); int a, c, d; short b = -1; void foo () { b++; } void bar () { l1: foo (); d = -3; for (a = 0; a > -3; a = d) c |= b; if (b) goto l1; } int main () { b++; l2: if (b) goto l2; bar (); printf ("%d\n", c); return 0; }