[Bug c/40907] New: -O2 generates incorrect code on i386
When compiling Scheme 48 with -O2, an overflow check in the internal arithmetic gets elided. This bug showed up sometime after gcc 4.0.1. It's in 4.4.1, and in the 4.5-20090723 snapshot. It's been seen on 32-bit Linux and 32-bit FreeBSD. The code snippet in question in c/scheme48vm-32.c is this: L12553: { b_1970X = arg0K0; lo_a_1971X = 65535 & a_1687X; lo_b_1972X = 65535 & b_1970X; hi_a_1973X = 65535 & (((a_1687X)>>16)); hi_b_1974X = 65535 & (((b_1970X)>>16)); lo_c_1975X = SMALL_MULTIPLY(lo_a_1971X, lo_b_1972X); v_1976X = SMALL_MULTIPLY(lo_a_1971X, hi_b_1974X); v_1977X = SMALL_MULTIPLY(lo_b_1972X, hi_a_1973X); mid_c_1978X = v_1976X + v_1977X; c_1979X = lo_c_1975X + (((mid_c_1978X)<<16)); if ((0 < hi_a_1973X)) { if ((0 < hi_b_1974X)) { val_1980X = integer_multiply(arg2_1113X, y_1114X); SvalS = val_1980X; Scode_pointerS = ((Scode_pointerS) + 1); arg3K0 = (Scode_pointerS); goto L32913;} else { goto L12595;}} else { goto L12595;}} ... L12595: { if ((536870911 < lo_c_1975X)) { val_2153X = integer_multiply(arg2_1113X, y_1114X); SvalS = val_2153X; Scode_pointerS = ((Scode_pointerS) + 1); arg3K0 = (Scode_pointerS); goto L32913;} else { if ((lo_c_1975X < 0)) { That last test never gets run, and the consequent code does not get run, even when lo_c_1975X is negative. I've not been able to boil the code down to a smaller snippet: Smaller programs containing this code compile OK. -- Summary: -O2 generates incorrect code on i386 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sperber at deinprogramm dot de GCC build triplet: i386-unknown-freebsd7.2 GCC host triplet: i386-unknown-freebsd7.2 GCC target triplet: i386-unknown-freebsd7.2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40907
[Bug c/40907] -O2 generates incorrect code on i386
--- Comment #1 from sperber at deinprogramm dot de 2009-07-29 17:37 --- Created an attachment (id=18271) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18271&action=view) preprocessed source file gcc -v output: kramer[420] gcc -v -save-temps -c -DHAVE_CONFIG_H -D__COMPILING_SCHEME48_ITSELF__ -DS48_HOST_ARCHITECTURE=\"i386-unknown-freebsd7.2\" -I ./c -I../s48/c -I../s48/c/net -I../s48/c/bibop -g -O2 -pthread -o c/scheme48vm-32.o ../s48/c/scheme48vm-32.c Using built-in specs. Target: i386-unknown-freebsd7.2 Configured with: ./configure --prefix=/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723 --with-gmp=/afs/informatik.uni-tuebingen.de/i386_fbsd70 --with-mpfr=/afs/informatik.uni-tuebingen.de/i386_fbsd72 Thread model: posix gcc version 4.5.0 20090723 (experimental) (GCC) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-DHAVE_CONFIG_H' '-D__COMPILING_SCHEME48_ITSELF__' '-DS48_HOST_ARCHITECTURE="i386-unknown-freebsd7.2"' '-I' './c' '-I../s48/c' '-I../s48/c/net' '-I../s48/c/bibop' '-g' '-O2' '-pthread' '-o' 'c/scheme48vm-32.o' '-mtune=i386' /afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/libexec/gcc/i386-unknown-freebsd7.2/4.5.0/cc1 -E -quiet -v -I ./c -I../s48/c -I../s48/c/net -I../s48/c/bibop -DHAVE_CONFIG_H -D__COMPILING_SCHEME48_ITSELF__ -DS48_HOST_ARCHITECTURE="i386-unknown-freebsd7.2" ../s48/c/scheme48vm-32.c -mtune=i386 -g -fworking-directory -O2 -fpch-preprocess -o scheme48vm-32.i ignoring nonexistent directory "/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/lib/gcc/i386-unknown-freebsd7.2/4.5.0/../../../../i386-unknown-freebsd7.2/include" #include "..." search starts here: #include <...> search starts here: ./c ../s48/c ../s48/c/net ../s48/c/bibop /usr/local/include /afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/include /afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/lib/gcc/i386-unknown-freebsd7.2/4.5.0/include /afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/lib/gcc/i386-unknown-freebsd7.2/4.5.0/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-DHAVE_CONFIG_H' '-D__COMPILING_SCHEME48_ITSELF__' '-DS48_HOST_ARCHITECTURE="i386-unknown-freebsd7.2"' '-I' './c' '-I../s48/c' '-I../s48/c/net' '-I../s48/c/bibop' '-g' '-O2' '-pthread' '-o' 'c/scheme48vm-32.o' '-mtune=i386' /afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/libexec/gcc/i386-unknown-freebsd7.2/4.5.0/cc1 -fpreprocessed scheme48vm-32.i -quiet -dumpbase scheme48vm-32.c -mtune=i386 -auxbase-strip c/scheme48vm-32.o -g -O2 -version -o scheme48vm-32.s GNU C (GCC) version 4.5.0 20090723 (experimental) (i386-unknown-freebsd7.2) compiled by GNU C version 4.5.0 20090723 (experimental), GMP version 4.2.4, MPFR version 2.4.1 GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 GNU C (GCC) version 4.5.0 20090723 (experimental) (i386-unknown-freebsd7.2) compiled by GNU C version 4.5.0 20090723 (experimental), GMP version 4.2.4, MPFR version 2.4.1 GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: 2ffc104588e5268bc0421635a8aaa323 COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-DHAVE_CONFIG_H' '-D__COMPILING_SCHEME48_ITSELF__' '-DS48_HOST_ARCHITECTURE="i386-unknown-freebsd7.2"' '-I' './c' '-I../s48/c' '-I../s48/c/net' '-I../s48/c/bibop' '-g' '-O2' '-pthread' '-o' 'c/scheme48vm-32.o' '-mtune=i386' as -o c/scheme48vm-32.o scheme48vm-32.s COMPILER_PATH=/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/libexec/gcc/i386-unknown-freebsd7.2/4.5.0/:/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/libexec/gcc/i386-unknown-freebsd7.2/4.5.0/:/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/libexec/gcc/i386-unknown-freebsd7.2/:/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/lib/gcc/i386-unknown-freebsd7.2/4.5.0/:/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/lib/gcc/i386-unknown-freebsd7.2/ LIBRARY_PATH=/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/lib/gcc/i386-unknown-freebsd7.2/4.5.0/:/afs/informatik.uni-tuebingen.de/i386_fbsd72/gcc-4.5-20090723/lib/gcc/i386-unknown-freebsd7.2/4.5.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-save-temps' '-c' '-DHAVE_CONFIG_H' '-D__COMPILING_SCHEME48_ITSELF__' '-DS48_HOST_ARCHITECTURE="i386-unknown-freebsd7.2"' '-I' './c' '-I../s48/c' '-I../s48/c/net' '-I../s48/c/bibop' '-g' '-O2' '-pthread' '-o' 'c/scheme48vm-32.o' '-mtune=i386' -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40907
[Bug c/40907] -O2 generates incorrect code on i386
--- Comment #4 from sperber at deinprogramm dot de 2009-07-29 17:42 --- (From update of attachment 18271) In the preprocessed file, the test that gets elided is in line 20307. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40907