https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89008
Bug ID: 89008 Summary: O2 and O1 results differ for simple test Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: konstantin.vladimirov at gmail dot com Target Milestone: --- Simple test: ---- #include <stdlib.h> unsigned long a, c; unsigned b; int d, e; long f() { unsigned long g = 0; for (d = 0; d < 5; d += 2) for (e = 0; e < 5; e += 3) { c = 4 + b; g = -b - b; b = 5 * (b << 24); } a = g; return 0; } int main() { f(); if (a) abort(); } --- Obviously, b initially 0 and 5*(b<<24) is 0 too on every iteration. But compile and run it with gcc 8.1 > gcc -O1 min-05.c > a.out > gcc -O2 min-05.c > a.out Aborted Compiler information: > gcc --verbose COLLECT_GCC=/apps/gcc/8.1.0/.bin/gcc COLLECT_LTO_WRAPPER=/apps/gcc/8.1.0/.bin/../libexec/gcc/x86_64-suse-linux/8.1.0/lto-wrapper Target: x86_64-suse-linux Configured with: ./configure --prefix=/apps/gcc/8.1.0 --libdir=/apps/gcc/8.1.0/lib64 --libexecdir=/apps/gcc/8.1.0/libexec --bindir=/apps/gcc/8.1.0/bin --with-isl=/apps/gcc/8.1.0 --with-libelf=/apps/gcc/8.1.0 --with-mpfr=/apps/gcc/8.1.0 --with-gmp=/apps/gcc/8.1.0 --with-mpc=/apps/gcc/8.1.0 --disable-gnu-unique-object --enable-gold=yes --enable-lto --enable-languages=c,c++,objc,fortran --build=x86_64-suse-linux --host=x86_64-suse-linux --target=x86_64-suse-linux --enable-libotm --disable-multilib --disable-bootstrap --disable-libstdcxx-pch Thread model: posix gcc version 8.1.0 (GCC)