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]

[PATCH]: Obvious fix to combine_stack_adjustments




I appreciate that this fix is another borderline case during the freeze,
but I believe it should be obvious.  GCC can occassionally emit a stack
adjust of zero bytes.  An example is given by the following test case:

double foo (void);
void bar (double);

void
test (void)
{
  bar (foo ());
}

which shows the problem under i686-pc-linux-gnu with "-O" on GCC 3.0.x
or with an additional "-march=i386" (or i486 or i586, but i686 is OK)
on mainline.  This example generates the following assembly:

	...
	subl	$24, %esp
	call	foo
	addl	$0, %esp	<- not required
	fstpl	(%esp)
	call	bar
	...

The redundant instruction is created by combine_stack_adjustments.
The simple patch below calls delete_insn on last_sp_set whenever
last_sp_adjust is zero and there are no further stack adjustments
that can be combined with it.

I also took the liberty of cleaning up part of this function that
didn't realize that delete_insn is now CFG aware, and maintains
bb->head itself (this wasn't done at other places in the same
function).


Tested by a "make bootstrap" and "make -k check" on i686-pc-linux-gnu
with no new regressions.  To double check the code was being exercised
I also tried a "make BOOT_CFLAGS="-g -O2 -march=i386" bootstrap", also
without problems.  [regmove's copyright already includes 2002].


Is this an obvious enough bug fix for mainline?



2002-01-02  Roger Sayle <roger@eyesopen.com>
	* regmove.c (combine_stack_adjustments_for_block): Avoid
	emitting a stack adjustment of zero bytes.  Let delete_insn
	update bb->head.


*** gcc/gcc/regmove.c	Wed Jan  2 13:36:59 2002
--- patch6/gcc/regmove.c	Wed Jan  2 20:11:02 2002
*************** combine_stack_adjustments_for_block (bb)
*** 2419,2424 ****
--- 2419,2426 ----
  		}

  	      /* Combination failed.  Restart processing from here.  */
+               if (last_sp_set && !last_sp_adjust)
+                 delete_insn (last_sp_set);
  	      free_csa_memlist (memlist);
  	      memlist = NULL;
  	      last_sp_set = insn;
*************** combine_stack_adjustments_for_block (bb)
*** 2449,2458 ****
  							 stack_pointer_rtx),
  				  0))
  	    {
- 	      if (last_sp_set == bb->head)
- 		bb->head = NEXT_INSN (last_sp_set);
  	      delete_insn (last_sp_set);
-
  	      free_csa_memlist (memlist);
  	      memlist = NULL;
  	      last_sp_set = NULL_RTX;
--- 2451,2457 ----
*************** combine_stack_adjustments_for_block (bb)
*** 2477,2482 ****
--- 2476,2483 ----
  	  && (GET_CODE (insn) == CALL_INSN
  	      || reg_mentioned_p (stack_pointer_rtx, PATTERN (insn))))
  	{
+           if (last_sp_set && !last_sp_adjust)
+             delete_insn (last_sp_set);
  	  free_csa_memlist (memlist);
  	  memlist = NULL;
  	  last_sp_set = NULL_RTX;
*************** combine_stack_adjustments_for_block (bb)
*** 2493,2496 ****
--- 2494,2499 ----

    if (pending_delete)
      delete_insn (pending_delete);
+   if (last_sp_set && !last_sp_adjust)
+     delete_insn (last_sp_set);
  }


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-438-3470


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