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]

regmove patch



I'd like y'all to take a quick look at this patch to regmove to verify
that I'm not doing anything totally stupid.  I selected you because I
know you have both worked on regmove in the past :-)  Your comments
would be greatly appreciated.


The background.

Assume that we are in optimize_reg_copy_1 and that we have found
a case were SRC dies before either SRC or DEST is modified.  Assume
that DEST does not originally cross any calls.

So, we're scanning forward from INSN replacing instances of SRC with
DEST as we go.  Also assume that we pass a death note for DEST.

Assume that we cross a call during the scan, which causes us to
increment n_calls and d_n_calls.

After crossing the call assume we find an insn where we can successfully
replace SRC with DEST.  So we have just lengthened the lifetime of
DEST and made is cross a call.  But note that we do not update the
REG_LIVE_LENGTH or REG_N_CALLS_CROSSED yet.

We continue scanning and assume that we find an insn which references
SRC, but where we can not replace SRC with DEST.  We set FAILED to one.

Eventually we stop the search.   Then we update REG_LIVE_LENGTH and
REG_N_CALLS_CROSSED if and only if FAILED is zero.

Since in our case FAILED is one, we never update REG_N_CALLS_CROSSED
even though we did actually make DEST cross a call.

And as a result, for the testcase I'm working with, we abort is
caller-save because we have a call-clobbered hard reg live across
a CALL_INSN.

As far as I can tell this is a latent bug that we've been lucky enough
to never trigger.

The patch is pretty simple, we update REG_LIVE_LENGTH and REG_N_CALLS_CROSSED
when we make a successful substitution.


	* regmove.c (optimize_reg_copy_1): Update REG_N_CALLS_CROSSED
	and REG_LIVE_LENGTH as successful substitutions are made.

Index: regmove.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/regmove.c,v
retrieving revision 1.28.2.1
diff -c -3 -p -r1.28.2.1 regmove.c
*** regmove.c	1998/07/26 00:03:56	1.28.2.1
--- regmove.c	1998/08/18 08:15:09
*************** optimize_reg_copy_1 (insn, dest, src)
*** 288,299 ****
  							     PATTERN (q))))
  		    {
  		      /* We assume that a register is used exactly once per
! 			 insn in the updates below.  If this is not correct,
! 			 no great harm is done.  */
  		      if (sregno >= FIRST_PSEUDO_REGISTER)
! 			REG_N_REFS (sregno) -= loop_depth;
  		      if (dregno >= FIRST_PSEUDO_REGISTER)
! 			REG_N_REFS (dregno) += loop_depth;
  		    }
  		  else
  		    {
--- 288,330 ----
  							     PATTERN (q))))
  		    {
  		      /* We assume that a register is used exactly once per
! 			 insn in the REG_N_REFS updates below.  If this is not
! 			 correct, no great harm is done.
! 
! 
! 			 We do not undo this substitution if something later
! 			 fails.  Therefore, we must update the other REG_N_*
! 			 counters now to keep them accurate.  */
  		      if (sregno >= FIRST_PSEUDO_REGISTER)
! 			{
! 			  REG_N_REFS (sregno) -= loop_depth;
! 
! 			  if (REG_LIVE_LENGTH (sregno) >= 0)
! 			    {
! 			      REG_LIVE_LENGTH (sregno) -= length;
! 			      /* REG_LIVE_LENGTH is only an approximation after
! 				 combine if sched is not run, so make sure that
! 				 we still have a reasonable value.  */
! 			      if (REG_LIVE_LENGTH (sregno) < 2)
! 				REG_LIVE_LENGTH (sregno) = 2;
! 			    }
! 
! 			  REG_N_CALLS_CROSSED (sregno) -= n_calls;
! 			}
! 
  		      if (dregno >= FIRST_PSEUDO_REGISTER)
! 			{
! 			  if (REG_LIVE_LENGTH (dregno) >= 0)
! 			    REG_LIVE_LENGTH (dregno) += d_length;
! 
! 			  REG_N_CALLS_CROSSED (dregno) += d_n_calls;
! 			}
! 
! 		      /* We've done a substitution, clear the counters.  */
! 		      length = 0;
! 		      d_length = 0;
! 		      n_calls = 0;
! 		      d_n_calls = 0;
  		    }
  		  else
  		    {





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