I have found a problem with GCC3.2 and GCC3.3 when -fomit-frame-pointer and -O2 are both used. The bug seems to be concerning the registers allocation that seems erroneous. The problem does not exist with GCC2.95. It goes away if either -fomit-frame-pointer or -O2 are disabled. *** Operating system: ===================== $ uname -a Linux owens.inria.fr 2.4.21 #1 Tue Jun 17 16:26:21 CEST 2003 i686 GNU/Linux *** GCC version: ================ gcc -v Reading specs from /usr/lib/gcc-lib/i386-linux/3.3/specs Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i386-linux Thread model: posix gcc version 3.3 (Debian) *** Source code: ================ int hux(int x){ if(x){ foo( 4 ); return x; } failure_then_exit(x); } *** GCC Command line: ===================== gcc -O2 -fomit-frame-pointer foo.c *** Preprocessed source file: ============================= $ gcc -fomit-frame-pointer foo.c -S -O2 -save-temps $ cat foo.i # 1 "foo.c" # 1 "<built-in>" # 1 "<command line>" # 1 "foo.c" int hux(int x) { if(x) { foo( 4 ); return x; } failure_then_exit(x); } *** Assembly file (that I known you don't want bug that shows the bug): ======================================================================= $ cat foo.s .file "foo.c" .text .p2align 2,,3 .globl hux .type hux, @function hux: pushl %ebx subl $8, %esp movl 16(%esp), %ebx testl %ebx, %ebx je .L2 subl $12, %esp pushl $4 call foo # <-- HERE, THE REGISTER EAX IS NOT .L3: # RELOADED !!! addl $24, %esp popl %ebx ret .p2align 2,,3 .L2: subl $12, %esp pushl $0 call failure_then_exit jmp .L3 .size hux, .-hux .ident "GCC: (GNU) 3.3 (Debian)"
Confirmed as a regression from GCC 3.0.4 present on all versions since then.
On the mainline (20030623) I get correct code: tin:~/src/gnu/gcctest>gcc -O2 -fomit-frame-pointer -S -o - pr11304.c -march=i386 - mtune=i386 .file "pr11304.c" .text .p2align 2,,3 .globl hux .type hux, @function hux: pushl %ebx subl $8, %esp movl 16(%esp), %ebx testl %ebx, %ebx je .L2 subl $12, %esp pushl $4 call foo addl $16, %esp addl $8, %esp movl %ebx, %eax ;<--- here eax is reloaded popl %ebx ret .p2align 2,,3 .L2: subl $12, %esp pushl $0 call failure_then_exit addl $16, %esp addl $8, %esp popl %ebx ret .size hux, .-hux .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.4 20030623 (experimental)" But in 3.3.1 (20030616), 3.2.2, and 3.2.3, I get the wrong code.
Right, I should have said "in all released versions since then".
Subject: Bug 11304 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: ebotcazou@gcc.gnu.org 2003-07-03 18:04:30 Modified files: gcc : ChangeLog cfgcleanup.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: i386-call-1.c Log message: PR optimization/11304 Backport from mainline: 2003-04-18 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> * cfgcleanup.c (flow_find_cross_jump): Use INSN_P, not active_insn_p. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.633&r2=1.16114.2.634 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cfgcleanup.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.68.2.4&r2=1.68.2.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.216&r2=1.2261.2.217 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/i386-call-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.2.1
See http://gcc.gnu.org/ml/gcc-patches/2003-06/msg02798.html
Author: jakub Date: Tue Feb 5 22:00:29 2019 New Revision: 268562 URL: https://gcc.gnu.org/viewcvs?rev=268562&root=gcc&view=rev Log: PR rtl-optimization/11304 * gcc.target/i386/call-1.c (set_eax): Add "eax" clobber. * gcc.target/i386/call-2.c: New test. Added: trunk/gcc/testsuite/gcc.target/i386/call-2.c Modified: trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.target/i386/call-1.c
Author: jakub Date: Thu Feb 7 14:56:24 2019 New Revision: 268648 URL: https://gcc.gnu.org/viewcvs?rev=268648&root=gcc&view=rev Log: Backported from mainline 2019-02-05 Jakub Jelinek <jakub@redhat.com> PR rtl-optimization/11304 * gcc.target/i386/call-1.c (set_eax): Add "eax" clobber. * gcc.target/i386/call-2.c: New test. Added: branches/gcc-8-branch/gcc/testsuite/gcc.target/i386/call-2.c Modified: branches/gcc-8-branch/gcc/testsuite/ChangeLog branches/gcc-8-branch/gcc/testsuite/gcc.target/i386/call-1.c
Author: jakub Date: Fri Aug 30 11:43:04 2019 New Revision: 275102 URL: https://gcc.gnu.org/viewcvs?rev=275102&root=gcc&view=rev Log: Backported from mainline 2019-02-05 Jakub Jelinek <jakub@redhat.com> PR rtl-optimization/11304 * gcc.target/i386/call-1.c (set_eax): Add "eax" clobber. * gcc.target/i386/call-2.c: New test. Added: branches/gcc-7-branch/gcc/testsuite/gcc.target/i386/call-2.c Modified: branches/gcc-7-branch/gcc/testsuite/ChangeLog branches/gcc-7-branch/gcc/testsuite/gcc.target/i386/call-1.c