Bug 9771 - [3.3 Regression] [x86] wrong ebp optimisation
: [3.3 Regression] [x86] wrong ebp optimisation
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: rtl-optimization
: 3.2.2
: P3 normal
: 3.3.6
Assigned To: Not yet assigned to anyone
:
: patch, wrong-code
:
:
  Show dependency treegraph
 
Reported: 2003-02-20 11:36 UTC by daniel.diaz
Modified: 2004-11-30 04:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.3 4.0.0
Known to fail: 3.3.4
Last reconfirmed: 2004-03-12 06:53:02


Attachments
bug.c (1.48 KB, text/plain)
2003-05-21 15:17 UTC, daniel.diaz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description daniel.diaz 2003-02-20 11:36:01 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
Comment 1 Dara Hazeghi 2003-05-14 17:03:56 UTC
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
Comment 2 Andrew Pinski 2003-08-07 13:18:37 UTC
 *      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
Comment 3 CVS Commits 2004-09-14 22:52:45 UTC
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

Comment 4 Andrew Pinski 2004-09-14 23:35:43 UTC
Fixed.
Comment 5 Andrew Pinski 2004-09-23 16:44:29 UTC
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>.
Comment 6 CVS Commits 2004-09-24 16:50:06 UTC
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

Comment 7 Gabriel Dos Reis 2004-09-28 13:42:58 UTC
Adjust milestone
Comment 8 CVS Commits 2004-11-30 04:34:29 UTC
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

Comment 9 Andrew Pinski 2004-11-30 04:42:26 UTC
Fixed.