Improvement for update_equiv_regs

Joern Rennecke amylaar@cygnus.co.uk
Tue Feb 9 10:52:00 GMT 1999


> That's fine, too, but it requires a lot more patches.  Just running two
> testcases I found two different pieces of code that need patching:

I've just run the compile testsuite for one SH subtarget and found some
more places:

Tue Feb  9 18:23:29 1999  J"orn Rennecke <amylaar@cygnus.co.uk>

	* cse.c (cse_insn): Add a REG_EQUAL note if SRC is now function
	invariant.
	* combine.c (try_combine):  Add a REG_EQUAL note if
	SET_SRC (newpat) / SET_SRC (newi2pat) is function invariant.
	* function.c (fixup_var_refs_1, case ADDRESSOF): 
	Add REG_EQUAL note if source is function invariant.
	* explow.c (copy_to_mode_reg): Likewise.
	* optabs.c (expand_binop): Also add REG_EQUAL note to single-insn
	sequence.
	* emit-rtl.c (gen_sequence): Don't discard REG_NOTES.

Index: cse.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/cse.c,v
retrieving revision 1.164
diff -p -r1.164 cse.c
*** cse.c	1999/01/20 17:50:19	1.164
--- cse.c	1999/02/09 18:15:34
*************** cse_insn (insn, libcall_insn)
*** 7204,7209 ****
--- 7204,7228 ----
  	    }
  	}
  
+       /* Likewise if the new src is a function invariant.  */
+       else if (n_sets == 1 && GET_CODE (dest) == REG
+ 	  && function_invariant_p (src))
+ 	{
+ 	  rtx note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
+ 
+ 	  /* If there alerady was a REG_EQUAL note, don't replace its
+ 	     value if it is already a function invariant.  */
+ 	     
+ 	  if (note)
+ 	    {
+ 	      if (! function_invariant_p (XEXP (note, 0)))
+ 		XEXP (note, 0) = src;
+ 	    }
+ 	  else
+ 	    REG_NOTES (insn) = gen_rtx_EXPR_LIST (REG_EQUAL,
+ 						  src, REG_NOTES (insn));
+ 	}
+ 
        /* Now deal with the destination.  */
        do_not_record = 0;
        sets[i].inner_dest_loc = &SET_DEST (sets[0].rtl);
Index: combine.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/combine.c,v
retrieving revision 1.193
diff -p -r1.193 combine.c
*** combine.c	1999/01/20 17:50:18	1.193
--- combine.c	1999/02/09 18:15:38
*************** try_combine (i3, i2, i1)
*** 2628,2636 ****
      /* Update reg_nonzero_bits et al for any changes that may have been made
         to this insn.  */
  
      note_stores (newpat, set_nonzero_bits_and_sign_copies);
      if (newi2pat)
!       note_stores (newi2pat, set_nonzero_bits_and_sign_copies);
  
      /* If I3 is now an unconditional jump, ensure that it has a 
         BARRIER following it since it may have initially been a
--- 2628,2679 ----
      /* Update reg_nonzero_bits et al for any changes that may have been made
         to this insn.  */
  
+     {
+       rtx set = single_set (i3);
+       if (set && function_invariant_p (SET_SRC (set)))
+ 	{
+ 	  rtx note = find_reg_note (i3, REG_EQUAL, NULL_RTX);
+ 
+ 	  /* If there alerady was a REG_EQUAL note, don't replace its
+ 	     value if it is already a function invariant.  */
+ 
+ 	  if (note)
+ 	    {
+ 	      if (! function_invariant_p (XEXP (note, 0)))
+ 		XEXP (note, 0) = SET_SRC (set);
+ 	    }
+ 	  else
+ 	    REG_NOTES (i3)
+ 	      = gen_rtx_EXPR_LIST (REG_EQUAL, SET_SRC (set),
+ 				   REG_NOTES (i3));
+ 	}
+     }
      note_stores (newpat, set_nonzero_bits_and_sign_copies);
      if (newi2pat)
!       {
! 	rtx set;
! 
! 	note_stores (newi2pat, set_nonzero_bits_and_sign_copies);
! 
! 	set = single_set (i2);
! 	if (function_invariant_p (SET_SRC (set)))
! 	  {
! 	    rtx note = find_reg_note (i2, REG_EQUAL, NULL_RTX);
! 
! 	    /* If there alerady was a REG_EQUAL note, don't replace its
! 	       value if it is already a function invariant.  */
! 
! 	    if (note)
! 	      {
! 		if (! function_invariant_p (XEXP (note, 0)))
! 		  XEXP (note, 0) = SET_SRC (set);
! 	      }
! 	    else
! 	      REG_NOTES (i2)
! 		= gen_rtx_EXPR_LIST (REG_EQUAL, SET_SRC (set),
! 				     REG_NOTES (i2));
! 	  }
!       }
  
      /* If I3 is now an unconditional jump, ensure that it has a 
         BARRIER following it since it may have initially been a
Index: function.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/function.c,v
retrieving revision 1.186.2.1
diff -p -r1.186.2.1 function.c
*** function.c	1999/01/27 19:43:39	1.186.2.1
--- function.c	1999/02/09 18:15:40
*************** fixup_var_refs_1 (var, promoted_mode, lo
*** 1897,1902 ****
--- 1897,1903 ----
  	{
  	  /* Prevent sharing of rtl that might lose.  */
  	  rtx sub = copy_rtx (XEXP (var, 0));
+ 	  rtx set;
  
  	  start_sequence ();
  
*************** fixup_var_refs_1 (var, promoted_mode, lo
*** 1910,1915 ****
--- 1911,1936 ----
  
  	  emit_insn_before (gen_sequence (), insn);
  	  end_sequence ();
+ 
+ 	  /* See if we have single set with a function invariant source now.  */
+ 	  set = single_set (insn);
+ 	  if (set && function_invariant_p (SET_SRC (set)))
+ 	    {
+ 	      rtx note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
+ 
+ 	      /* If there alerady was a REG_EQUAL note, don't replace its
+ 		 value if it is already a function invariant.  */
+ 
+ 	      if (note)
+ 		{
+ 		  if (! function_invariant_p (XEXP (note, 0)))
+ 		    XEXP (note, 0) = SET_SRC (set);
+ 		}
+ 	      else
+ 		REG_NOTES (insn)
+ 		  = gen_rtx_EXPR_LIST (REG_EQUAL, SET_SRC (set),
+ 				       REG_NOTES (insn));
+ 	    }
  	}
        return;
  
Index: explow.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/explow.c,v
retrieving revision 1.76
diff -p -r1.76 explow.c
*** explow.c	1999/01/20 17:50:21	1.76
--- explow.c	1999/02/09 18:15:40
*************** copy_to_mode_reg (mode, x)
*** 670,676 ****
    if (GET_MODE (x) != mode && GET_MODE (x) != VOIDmode)
      abort ();
    if (x != temp)
!     emit_move_insn (temp, x);
    return temp;
  }
  
--- 670,695 ----
    if (GET_MODE (x) != mode && GET_MODE (x) != VOIDmode)
      abort ();
    if (x != temp)
!     {
!       rtx insn = emit_move_insn (temp, x);
! 
!       if (function_invariant_p (x))
! 	{
! 	  rtx note = find_reg_note (insn, REG_EQUAL, NULL_RTX);
! 
! 	  /* If there already was a REG_EQUAL note, don't replace its
! 	     value if it is already a function invariant.  */
! 
! 	  if (note)
! 	    {
! 	      if (! function_invariant_p (XEXP (note, 0)))
! 		XEXP (note, 0) = x;
! 	    }
! 	  else
! 	    REG_NOTES (insn)
! 	      = gen_rtx_EXPR_LIST (REG_EQUAL, x, REG_NOTES (insn));
! 	}
!     }
    return temp;
  }
  
Index: optabs.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/optabs.c,v
retrieving revision 1.107
diff -p -r1.107 optabs.c
*** optabs.c	1999/01/20 17:50:24	1.107
--- optabs.c	1999/02/09 18:15:41
*************** expand_binop (mode, binoptab, op0, op1, 
*** 453,459 ****
        int icode = (int) binoptab->handlers[(int) mode].insn_code;
        enum machine_mode mode0 = insn_operand_mode[icode][1];
        enum machine_mode mode1 = insn_operand_mode[icode][2];
!       rtx pat;
        rtx xop0 = op0, xop1 = op1;
  
        if (target)
--- 453,459 ----
        int icode = (int) binoptab->handlers[(int) mode].insn_code;
        enum machine_mode mode0 = insn_operand_mode[icode][1];
        enum machine_mode mode1 = insn_operand_mode[icode][2];
!       rtx pat, seq;
        rtx xop0 = op0, xop1 = op1;
  
        if (target)
*************** expand_binop (mode, binoptab, op0, op1, 
*** 505,522 ****
        pat = GEN_FCN (icode) (temp, xop0, xop1);
        if (pat)
  	{
! 	  /* If PAT is a multi-insn sequence, try to add an appropriate
! 	     REG_EQUAL note to it.  If we can't because TEMP conflicts with an
  	     operand, call ourselves again, this time without a target.  */
! 	  if (GET_CODE (pat) == SEQUENCE
! 	      && ! add_equal_note (pat, temp, binoptab->code, xop0, xop1))
  	    {
  	      delete_insns_since (last);
  	      return expand_binop (mode, binoptab, op0, op1, NULL_RTX,
  				   unsignedp, methods);
  	    }
  
! 	  emit_insn (pat);
  	  return temp;
  	}
        else
--- 505,527 ----
        pat = GEN_FCN (icode) (temp, xop0, xop1);
        if (pat)
  	{
! 	  /* Try to add an appropriate REG_EQUAL note.
! 	     If we can't because TEMP conflicts with an
  	     operand, call ourselves again, this time without a target.  */
! 	  if (GET_CODE (pat) != SEQUENCE)
! 	    seq
! 	      = gen_rtx_SEQUENCE (VOIDmode, gen_rtvec (1, make_insn_raw (pat)));
! 	  else
! 	    seq = pat;
! 	  if (! add_equal_note (seq, temp, binoptab->code, xop0, xop1)
! 	      && GET_CODE (pat) == SEQUENCE)
  	    {
  	      delete_insns_since (last);
  	      return expand_binop (mode, binoptab, op0, op1, NULL_RTX,
  				   unsignedp, methods);
  	    }
  
! 	  emit_insn (seq);
  	  return temp;
  	}
        else
Index: emit-rtl.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/emit-rtl.c,v
retrieving revision 1.123
diff -p -r1.123 emit-rtl.c
*** emit-rtl.c	1999/01/21 19:46:39	1.123
--- emit-rtl.c	1999/02/09 18:15:42
*************** gen_sequence ()
*** 3281,3287 ****
  	  || GET_CODE (first_insn) == JUMP_INSN
  	  /* Don't discard the call usage field.  */
  	  || (GET_CODE (first_insn) == CALL_INSN
! 	      && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX)))
      {
        NEXT_INSN (first_insn) = free_insn;
        free_insn = first_insn;
--- 3281,3289 ----
  	  || GET_CODE (first_insn) == JUMP_INSN
  	  /* Don't discard the call usage field.  */
  	  || (GET_CODE (first_insn) == CALL_INSN
! 	      && CALL_INSN_FUNCTION_USAGE (first_insn) == NULL_RTX))
!       /* Don't discard the REG_NOTES.  */
!       && REG_NOTES (first_insn) == NULL_RTX)
      {
        NEXT_INSN (first_insn) = free_insn;
        free_insn = first_insn;


More information about the Gcc-patches mailing list