Created attachment 29571 [details] Small test program exhibiting the problem If I'm cross-compiling the attached sample-program using gcc 4.7.2 for ARM on an x86-64 system, the resulting binary behaves wrongly if -O3 is used. Output with -O0: value: -23 best: -10000 a: -68 value: -22 best: -23 a: -23 Output with -O3: value: -23 best: -10000 a: -68 value: -22 best: -23 a: 65513 BUG
Created attachment 29572 [details] Preprocessed file Created using the following command: arm-unknown-linux-gnueabi-g++ -v -save-temps -O3 bug.cpp
Created attachment 29573 [details] Compiler output Output of arm-unknown-linux-gnueabi-g++ -v -save-temps -O3 bug.cpp
Also happens with GCC 4.7.1 and 4.6.3.
I can reproduce the wrong-code on armv5tel-linux-gnueabi with gcc-4.7-20130302 and gcc-4.6-20121109, but not with gcc-4.8-20130224. I can't reproduce on x86_64, sparc64, aarch64, or m68k.
The wrong-code stopped for 4.8 with r188526, the introduction and enabling of -ftree-coalesce-vars. At that point the wrong-code reappears with -O3 -fno-tree-coalesce-vars, however with current trunk those options give correct code. I'll investigate some more tomorrow.
The wrong-code with -O3 -fno-tree-coalesce-vars stopped occurring at r190284, Richard Biener's large "Allow anonymous SSA names" patch. The patch description mentions minor code generation differences, but it doesn't appear to contain actual wrong code fixes so the underlying issue may still be latent on trunk.