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]

PREFERRED_STACK_BOUNDARY/function calling code fix



Hi
Following function:
void
main ()
{
  t (1);
  t (1);
  t (1);
}
Results in following somewhat surprising code:
main:
	subl	$24, %esp
	pushl	$1
	call	t
	subl	$12, %esp
	pushl	$1
	call	t
	addl	$20, %esp
	pushl	$1
	call	t
	addl	$28, %esp
	ret
The purpose for such strange stack adjustments is pending_stack_adjust optimization,
that does wrong thinks when the aligning stack adjustment is necesary.
With this patch applied, resulting code is:

main:
	subl	$24, %esp
	pushl	$1
	call	t
	popl	%eax
	pushl	$1
	call	t
	popl	%eax
	pushl	$1
	call	t
	addl	$28, %esp
	ret

Still not perfect, but better :)

Wed Feb 23 12:54:07 CET 2000  Jan Hubicka  <jh@suse.cz>
	* calls.c (expand_call): Attempt to combine stack adjustments with
	pending stack adjustments.

*** calls.c.old	Tue Feb 22 18:25:49 2000
--- calls.c	Wed Feb 23 12:53:58 2000
*************** expand_call (exp, target, ignore)
*** 2277,2284 ****
  #ifdef PREFERRED_STACK_BOUNDARY
    /* If we push args individually in reverse order, perform stack alignment
       before the first push (the last arg).  */
!   if (argblock == 0)
!     anti_adjust_stack (GEN_INT (args_size.constant - unadjusted_args_size));
  #endif
  #endif
  
--- 2277,2298 ----
  #ifdef PREFERRED_STACK_BOUNDARY
    /* If we push args individually in reverse order, perform stack alignment
       before the first push (the last arg).  */
!   if (args_size.constant != unadjusted_args_size)
!     {
!       /* when the stack adjustment is pending,
! 	 we get better code by combining the adjustments.  */
!       if (pending_stack_adjust && !is_const)
! 	{
! 	  args_size.constant = (unadjusted_args_size
! 			        + ((pending_stack_adjust + args_size.constant
! 				    - unadjusted_args_size)
! 			           % (preferred_stack_boundary / BITS_PER_UNIT)));
! 	  pending_stack_adjust -= args_size.constant - unadjusted_args_size;
! 	  do_pending_stack_adjust ();
! 	}
!       else if (argblock == 0)
! 	anti_adjust_stack (GEN_INT (args_size.constant - unadjusted_args_size));
!     }
  #endif
  #endif
  

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