This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

x86 stack frame padding


	void f1() { }
	void f2() { int x = 0; if (x) foo(); }

F1 and F2 should, with -fomit-frame-pointer, compile to the
same thing.  Namely, just the return instruction.  Unfortunately:

f1:
	ret

f2:
	subl	$12, %esp
	addl	$12, %esp
	ret

Where in the world did that come from, you say?  From the 
padding to align the stack for the function call, obviously.
What function call?  The one we got rid of.  Doh.

This one I'm applying to 3.1 as well.


r~


	* config/i386/i386.c (ix86_compute_frame_layout): Do not add
	bottom alignment for leaf functions.

Index: config/i386/i386.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.409
diff -c -p -d -r1.409 i386.c
*** config/i386/i386.c	25 May 2002 01:56:57 -0000	1.409
--- config/i386/i386.c	28 May 2002 08:24:41 -0000
*************** ix86_compute_frame_layout (frame)
*** 4138,4145 ****
  
    offset += size;
  
!   /* Add outgoing arguments area.  */
!   if (ACCUMULATE_OUTGOING_ARGS)
      {
        offset += current_function_outgoing_args_size;
        frame->outgoing_arguments_size = current_function_outgoing_args_size;
--- 4138,4146 ----
  
    offset += size;
  
!   /* Add outgoing arguments area.  Can be skipped if we eliminated
!      all the function calls as dead code.  */
!   if (ACCUMULATE_OUTGOING_ARGS && !current_function_is_leaf)
      {
        offset += current_function_outgoing_args_size;
        frame->outgoing_arguments_size = current_function_outgoing_args_size;
*************** ix86_compute_frame_layout (frame)
*** 4147,4155 ****
    else
      frame->outgoing_arguments_size = 0;
  
!   /* Align stack boundary.  */
!   frame->padding2 = ((offset + preferred_alignment - 1)
! 		     & -preferred_alignment) - offset;
  
    offset += frame->padding2;
  
--- 4148,4159 ----
    else
      frame->outgoing_arguments_size = 0;
  
!   /* Align stack boundary.  Only needed if we're calling another function.  */
!   if (!current_function_is_leaf)
!     frame->padding2 = ((offset + preferred_alignment - 1)
! 		       & -preferred_alignment) - offset;
!   else
!     frame->padding2 = 0;
  
    offset += frame->padding2;
  


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]