Bug 18759 - [x86] using both -fomit-frame-pointer and -momit-leaf-frame-pointer enables frame pointers for non-leaf functions
Summary: [x86] using both -fomit-frame-pointer and -momit-leaf-frame-pointer enables f...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.4.3
: P2 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2004-12-01 16:45 UTC by Markus F.X.J. Oberhumer
Modified: 2005-07-23 22:49 UTC (History)
4 users (show)

See Also:
Host: i386-linux-gnu
Target:
Build:
Known to work: 4.0.0
Known to fail: 2.95.3 3.2.3 3.3.6 3.4.3
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus F.X.J. Oberhumer 2004-12-01 16:46:00 UTC
Using both -fomit-frame-pointer and -momit-leaf-frame-pointer _enables_ frame
pointers for non-leaf functions.
 
> cat x.c
int foo(void) { return 0; }
int bar(void) { return foo() + 1; }

> gcc-3.4 -O2 -fomit-frame-pointer -c x.c && objdump -d x.o

  [...]
00000010 <bar>:
  10:   e8 fc ff ff ff          call   11 <bar+0x1>
  15:   40                      inc    %eax
  16:   c3                      ret
  [...]

> gcc-3.4 -O2 -fomit-frame-pointer -momit-leaf-frame-pointer -c x.c && objdump
-d x.o

  [...]
00000010 <bar>:
  10:   55                      push   %ebp
  11:   89 e5                   mov    %esp,%ebp
  13:   e8 fc ff ff ff          call   14 <bar+0x4>
  18:   5d                      pop    %ebp
  19:   40                      inc    %eax
  1a:   c3                      ret
  [...]



This check in i386.c ix86_frame_pointer_required() could be the cause:

  /* In override_options, TARGET_OMIT_LEAF_FRAME_POINTER turns off
     the frame pointer by default.  Turn it back on now if we've not
     got a leaf function.  */
  if (TARGET_OMIT_LEAF_FRAME_POINTER
      && (!current_function_is_leaf))
    return 1;
Comment 1 Giovanni Bajo 2004-12-01 23:02:58 UTC
Roger?
Comment 2 GCC Commits 2004-12-02 21:19:42 UTC
Subject: Bug 18759

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	sayle@gcc.gnu.org	2004-12-02 21:19:35

Modified files:
	gcc            : ChangeLog 
	gcc/config/i386: i386.c 

Log message:
	PR target/18759
	* config/i386/i386.c (override_options): If -fomit-frame-pointer has
	already been specified, ignore the -momit-leaf-frame-pointer option.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6689&r2=2.6690
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&r1=1.747&r2=1.748

Comment 3 Andrew Pinski 2004-12-02 21:22:15 UTC
Fixed on the mainline.
Comment 4 Markus F.X.J. Oberhumer 2004-12-02 21:28:03 UTC
Might this be a candidate for 3.3/3.4 backporting ?

Comment 5 Joseph S. Myers 2005-05-03 21:04:32 UTC
I'm backporting this patch to csl-sol210-3_4-branch.  In theory there's a
regression on vanilla 3.4 if you build pr9771-1.c with -momit-leaf-frame-pointer
in addition to the options specified in that testcase (then this bug causes it
to fail); it's just the Solaris 10 port which isn't in vanilla 3.4 which makes
this more visible by having -momit-leaf-frame-pointer on by default when optimizing.
Comment 6 GCC Commits 2005-05-03 21:54:23 UTC
Subject: Bug 18759

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	csl-sol210-3_4-branch
Changes by:	jsm28@gcc.gnu.org	2005-05-03 21:54:14

Modified files:
	.              : ChangeLog.csl 
	gcc/config/i386: i386.c 

Log message:
	Backport from mainline:
	2004-12-02  Roger Sayle  <roger@eyesopen.com>
	
	PR target/18759
	* config/i386/i386.c (override_options): If -fomit-frame-pointer has
	already been specified, ignore the -momit-leaf-frame-pointer option.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/ChangeLog.csl.diff?cvsroot=gcc&only_with_tag=csl-sol210-3_4-branch&r1=1.1.2.16&r2=1.1.2.17
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/i386/i386.c.diff?cvsroot=gcc&only_with_tag=csl-sol210-3_4-branch&r1=1.635.2.15.2.2&r2=1.635.2.15.2.3