This is for "gcc version 4.3.0 (GCC)" This is very likely related to 35729 and 35762. This code: extern int bar (void); volatile int g_156; int foo (void) { if (bar ()) return 0; else return g_156; } Compiled with: gcc -O1 -S foo.c Gives: foo: pushl %ebp movl %esp, %ebp subl $8, %esp call bar cmpl $1, %eax sbbl %eax, %eax andl g_156, %eax leave ret The unconditional load from volatile g_156 is incorrect.
This works for me on the trunk. I either get a cmove or a branch.
I'm not sure what is going on, I get the same code as before using r141907 on Ubuntu Hardy on x86. What compiler options are you using and what platform? regehr@john-home:~$ current-gcc -O -S vol.c -o - .file "vol.c" .text .globl foo .type foo, @function foo: pushl %ebp movl %esp, %ebp subl $8, %esp call bar cmpl $1, %eax sbbl %eax, %eax andl g_156, %eax leave ret .size foo, .-foo .comm g_156,4,4 .ident "GCC: (GNU) 4.4.0 20081116 (experimental)" .section .note.GNU-stack,"",@progbits regehr@john-home:~$ regehr@john-home:~$ current-gcc -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../configure --program-prefix=current- --enable-languages=c,c++ --prefix=/home/regehr Thread model: posix gcc version 4.4.0 20081116 (experimental) (GCC) regehr@john-home:~$
*** Bug 35762 has been marked as a duplicate of this bug. ***
Confirmed, -march=i386 -mtune=i686 is needed to confirm the bug in general. GCC is producing a "conditional move" for the code even though it is invalid to produce such a thing.