GCC Bugzilla – Bug 9771
[3.3 Regression] [x86] wrong ebp optimisation
Last modified: 2004-11-30 04:42:26 UTC
I use ebp for a global variable B which is a pointer. Inside a function foo(): 1) the value of B (ebp) is saved in a local variable 'adr' 2) the object pointed by adr (=B=ebp) is saved in a local variable 'save'. 3) the object pointed by adr is set to the value 123. 4) a function bar() is called which changes B (i.e. ebp). 5) when returning in foo() the object pointed by 'adr' is restored to 'save'. Unfortunately gcc generates a code that restores the object pointed by ebp (and not adr). Release: gcc version 3.2.2 20030213 (Red Hat Linux 8.0 3.2.2-1) Environment: Linux lima.univ-paris1.fr 2.4.18-18.7.x #1 Wed Nov 13 20:29:30 EST 2002 i686 unknown How-To-Repeat: use: gcc -o bug bug.c for a correct answer which gives: x:10 y:20 use: gcc -DREG='"ebp"' -ffixed-ebp -fomit-frame-pointer -mpreferred-stack-boundary=2 -O -o bug bug.c which gives the wrong result: x:123 y:10
From: Dara Hazeghi <dhazeghi@yahoo.com> To: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org Cc: Subject: Re: optimization/9771: [x86] wrong ebp optimisation Date: Wed, 14 May 2003 17:03:56 -0700 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- trail&database=gcc&pr=9771 Hello, I can confirm that with gcc 3.2, 3.3 branch and mainline (20030511) I can reproduce the behavior in this report. Dara
* pushl %esi * pushl %ebx * movl (%ebp), %esi * movl $123, (%ebp) * call bar * movl %esi, (%ebp) bug: restores y and not x !!! * popl %ebx * popl %esi * ret
Subject: Bug 9771 CVSROOT: /cvs/gcc Module name: gcc Changes by: sayle@gcc.gnu.org 2004-09-14 22:52:41 Modified files: gcc : ChangeLog regclass.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: pr9771-1.c Log message: PR rtl-optimization/9771 * regclass.c (CALL_REALLY_USED_REGNO_P): New macro to eliminate conditional compilation in init_reg_sets_1. (init_reg_sets_1): Let global_regs[i] take priority over the frame (but not stack) pointer exceptions to regs_invalidated_by_call. (globalize_reg): Globalizing a fixed register may need to update regs_invalidated_by_call. * gcc.dg/pr9771-1.c: New test case. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5449&r2=2.5450 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/regclass.c.diff?cvsroot=gcc&r1=1.195&r2=1.196 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4287&r2=1.4288 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr9771-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
Fixed.
Reopening because this is a regression. Patch to back port to 3.4.x: <http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02398.html>.
Subject: Bug 9771 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_4-branch Changes by: sayle@gcc.gnu.org 2004-09-24 16:49:38 Modified files: gcc : ChangeLog regclass.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: pr9771-1.c Log message: PR rtl-optimization/9771 * regclass.c (CALL_REALLY_USED_REGNO_P): New macro to eliminate conditional compilation in init_reg_sets_1. (init_reg_sets_1): Let global_regs[i] take priority over the frame (but not stack) pointer exceptions to regs_invalidated_by_call. (globalize_reg): Globalizing a fixed register may need to update regs_invalidated_by_call. * gcc.dg/pr9771-1.c: New test case. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.634&r2=2.2326.2.635 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/regclass.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.183&r2=1.183.4.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.272&r2=1.3389.2.273 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr9771-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.10.1
Adjust milestone
Subject: Bug 9771 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-3_3-branch Changes by: sayle@gcc.gnu.org 2004-11-30 04:34:22 Modified files: gcc : ChangeLog regclass.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/gcc.dg: pr9771-1.c Log message: PR rtl-optimization/9771 * regclass.c (CALL_REALLY_USED_REGNO_P): New macro to eliminate conditional compilation in init_reg_sets_1. (init_reg_sets_1): Let global_regs[i] take priority over the frame (but not stack) pointer exceptions to regs_invalidated_by_call. (globalize_reg): Globalizing a fixed register may need to update regs_invalidated_by_call. * gcc.dg/pr9771-1.c: New test case. 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.1028&r2=1.16114.2.1029 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/regclass.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.160.4.6&r2=1.160.4.7 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.386&r2=1.2261.2.387 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr9771-1.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.44.1