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]

RFC: remove find_replacement. (pr24912 / pr25335)


You introduced find_replacement in April 1992, presumably to solve the problem that the replacements are not applied at the time that reloads are being made. Since then its use has spread over a number of functions in the middle-end and in the backends, yet still new code is introduced that doesn't work as it is called while replacements are pending, but it doesn't use find_replacements. I think a much simpler solution, which should also be more robust in the long term, is to apply all the replacements before we start to emit reload insns.
2006-01-31  J"orn Rennecke <joern.rennecke@st.com>

	* reload1.c (reload_as_needed): Call subst_reloads before
	emit_reload_insns.
	(gen_reload): Don't call find_replacement.
	* reload.c (find_replacement): Remove.
	* reload.h (find_replacement): Don't declare.
	* expr.c (emit_move_multi_word): Don't use find_replacement.
	* alpha.c (get_aligned_mem, get_unaligned_address): Likewise.
	* s390.c (s390_expand_plus_operand): Likewise.
	* s390.md (reload_outti, reload_outdi, reload_outdf): Likewise.
	* m68k.c (emit_move_sequence): Likewise.
	* arm.c (arm_reload_in_hi, arm_reload_out_hi): Likewise.
	* pa.c (emit_move_sequence): Likewise.

Index: reload.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L reload.c	(revision 110439) -L reload.c	(working copy) .svn/text-base/reload.c.svn-base reload.c
--- reload.c	(revision 110439)
+++ reload.c	(working copy)
@@ -6121,69 +6121,6 @@ move_replacements (rtx *x, rtx *y)
       }
 }
 
-/* If LOC was scheduled to be replaced by something, return the replacement.
-   Otherwise, return *LOC.  */
-
-rtx
-find_replacement (rtx *loc)
-{
-  struct replacement *r;
-
-  for (r = &replacements[0]; r < &replacements[n_replacements]; r++)
-    {
-      rtx reloadreg = rld[r->what].reg_rtx;
-
-      if (reloadreg && r->where == loc)
-	{
-	  if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode)
-	    reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg));
-
-	  return reloadreg;
-	}
-      else if (reloadreg && r->subreg_loc == loc)
-	{
-	  /* RELOADREG must be either a REG or a SUBREG.
-
-	     ??? Is it actually still ever a SUBREG?  If so, why?  */
-
-	  if (REG_P (reloadreg))
-	    return gen_rtx_REG (GET_MODE (*loc),
-				(REGNO (reloadreg) +
-				 subreg_regno_offset (REGNO (SUBREG_REG (*loc)),
-						      GET_MODE (SUBREG_REG (*loc)),
-						      SUBREG_BYTE (*loc),
-						      GET_MODE (*loc))));
-	  else if (GET_MODE (reloadreg) == GET_MODE (*loc))
-	    return reloadreg;
-	  else
-	    {
-	      int final_offset = SUBREG_BYTE (reloadreg) + SUBREG_BYTE (*loc);
-
-	      /* When working with SUBREGs the rule is that the byte
-		 offset must be a multiple of the SUBREG's mode.  */
-	      final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (*loc)));
-	      final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (*loc)));
-	      return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg),
-				     final_offset);
-	    }
-	}
-    }
-
-  /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for
-     what's inside and make a new rtl if so.  */
-  if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS
-      || GET_CODE (*loc) == MULT)
-    {
-      rtx x = find_replacement (&XEXP (*loc, 0));
-      rtx y = find_replacement (&XEXP (*loc, 1));
-
-      if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1))
-	return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y);
-    }
-
-  return *loc;
-}
-
 /* Return nonzero if register in range [REGNO, ENDREGNO)
    appears either explicitly or implicitly in X
    other than being stored into (except for earlyclobber operands).
Index: reload.h
===================================================================
/usr/bin/diff -p -d -F^( -u -L reload.h	(revision 110439) -L reload.h	(working copy) .svn/text-base/reload.h.svn-base reload.h
--- reload.h	(revision 110439)
+++ reload.h	(working copy)
@@ -300,10 +300,6 @@ extern void copy_replacements (rtx, rtx)
 /* Change any replacements being done to *X to be done to *Y */
 extern void move_replacements (rtx *x, rtx *y);
 
-/* If LOC was scheduled to be replaced by something, return the replacement.
-   Otherwise, return *LOC.  */
-extern rtx find_replacement (rtx *);
-
 /* Nonzero if modifying X will affect IN.  */
 extern int reg_overlap_mentioned_for_reload_p (rtx, rtx);
 
Index: expr.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L expr.c	(revision 110439) -L expr.c	(working copy) .svn/text-base/expr.c.svn-base expr.c
--- expr.c	(revision 110439)
+++ expr.c	(working copy)
@@ -3046,7 +3046,7 @@ static rtx
 emit_move_multi_word (enum machine_mode mode, rtx x, rtx y)
 {
   rtx last_insn = 0;
-  rtx seq, inner;
+  rtx seq;
   bool need_clobber;
   int i;
       
@@ -3057,15 +3057,6 @@ emit_move_multi_word (enum machine_mode 
   if (push_operand (x, mode))
     x = emit_move_resolve_push (mode, x);
 
-  /* If we are in reload, see if either operand is a MEM whose address
-     is scheduled for replacement.  */
-  if (reload_in_progress && MEM_P (x)
-      && (inner = find_replacement (&XEXP (x, 0))) != XEXP (x, 0))
-    x = replace_equiv_address_nv (x, inner);
-  if (reload_in_progress && MEM_P (y)
-      && (inner = find_replacement (&XEXP (y, 0))) != XEXP (y, 0))
-    y = replace_equiv_address_nv (y, inner);
-
   start_sequence ();
 
   need_clobber = false;
Index: config/alpha/alpha.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L config/alpha/alpha.c	(revision 110439) -L config/alpha/alpha.c	(working copy) config/alpha/.svn/text-base/alpha.c.svn-base config/alpha/alpha.c
--- config/alpha/alpha.c	(revision 110439)
+++ config/alpha/alpha.c	(working copy)
@@ -1494,7 +1494,7 @@ get_aligned_mem (rtx ref, rtx *paligned_
   if (reload_in_progress
       && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
     {
-      base = find_replacement (&XEXP (ref, 0));
+      base = XEXP (ref, 0);
       gcc_assert (memory_address_p (GET_MODE (ref), base));
     }
   else
@@ -1539,7 +1539,7 @@ get_unaligned_address (rtx ref, int extr
   if (reload_in_progress
       && ! memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
     {
-      base = find_replacement (&XEXP (ref, 0));
+      base = XEXP (ref, 0);
 
       gcc_assert (memory_address_p (GET_MODE (ref), base));
     }
Index: config/s390/s390.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L config/s390/s390.c	(revision 110439) -L config/s390/s390.c	(working copy) config/s390/.svn/text-base/s390.c.svn-base config/s390/s390.c
--- config/s390/s390.c	(revision 110439)
+++ config/s390/s390.c	(working copy)
@@ -2621,8 +2621,8 @@ s390_expand_plus_operand (rtx target, rt
   /* Check if any of the two operands is already scheduled
      for replacement by reload.  This can happen e.g. when
      float registers occur in an address.  */
-  sum1 = find_replacement (&XEXP (src, 0));
-  sum2 = find_replacement (&XEXP (src, 1));
+  sum1 = XEXP (src, 0);
+  sum2 = XEXP (src, 1);
   src = gen_rtx_PLUS (Pmode, sum1, sum2);
 
   /* If the address is already strictly valid, there's nothing to do.  */
@@ -2645,8 +2645,7 @@ s390_expand_plus_operand (rtx target, rt
 
       /* According to the way these invalid addresses are generated
          in reload.c, it should never happen (at least on s390) that
-         *neither* of the PLUS components, after find_replacements
-         was applied, is an address register.  */
+         *neither* of the PLUS components is an address register.  */
       if (sum1 == scratch && sum2 == scratch)
 	{
 	  debug_rtx (src);
Index: config/s390/s390.md
===================================================================
/usr/bin/diff -p -d -F^( -u -L config/s390/s390.md	(revision 110439) -L config/s390/s390.md	(working copy) config/s390/.svn/text-base/s390.md.svn-base config/s390/s390.md
--- config/s390/s390.md	(revision 110439)
+++ config/s390/s390.md	(working copy)
@@ -873,7 +873,7 @@ (define_expand "reload_outti"
   "TARGET_64BIT"
 {
   gcc_assert (MEM_P (operands[0]));
-  s390_load_address (operands[2], find_replacement (&XEXP (operands[0], 0)));
+  s390_load_address (operands[2], XEXP (operands[0], 0));
   operands[0] = replace_equiv_address (operands[0], operands[2]);
   emit_move_insn (operands[0], operands[1]);
   DONE;
@@ -1068,7 +1068,7 @@ (define_expand "reload_outdi"
   "!TARGET_64BIT"
 {
   gcc_assert (MEM_P (operands[0]));
-  s390_load_address (operands[2], find_replacement (&XEXP (operands[0], 0)));
+  s390_load_address (operands[2], XEXP (operands[0], 0));
   operands[0] = replace_equiv_address (operands[0], operands[2]);
   emit_move_insn (operands[0], operands[1]);
   DONE;
@@ -1533,7 +1533,7 @@ (define_expand "reload_outdf"
   "!TARGET_64BIT"
 {
   gcc_assert (MEM_P (operands[0]));
-  s390_load_address (operands[2], find_replacement (&XEXP (operands[0], 0)));
+  s390_load_address (operands[2], XEXP (operands[0], 0));
   operands[0] = replace_equiv_address (operands[0], operands[2]);
   emit_move_insn (operands[0], operands[1]);
   DONE;
Index: config/m68k/m68k.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L config/m68k/m68k.c	(revision 110439) -L config/m68k/m68k.c	(working copy) config/m68k/.svn/text-base/m68k.c.svn-base config/m68k/m68k.c
--- config/m68k/m68k.c	(revision 110439)
+++ config/m68k/m68k.c	(working copy)
@@ -2387,11 +2387,11 @@ emit_move_sequence (rtx *operands, enum 
     }
 
   if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
-      && ((tem = find_replacement (&XEXP (operand0, 0)))
+      && ((tem = XEXP (operand0, 0))
 	  != XEXP (operand0, 0)))
     operand0 = gen_rtx_MEM (GET_MODE (operand0), tem);
   if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
-      && ((tem = find_replacement (&XEXP (operand1, 0)))
+      && ((tem = XEXP (operand1, 0))
 	  != XEXP (operand1, 0)))
     operand1 = gen_rtx_MEM (GET_MODE (operand1), tem);
 
Index: config/arm/arm.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L config/arm/arm.c	(revision 110439) -L config/arm/arm.c	(working copy) config/arm/.svn/text-base/arm.c.svn-base config/arm/arm.c
--- config/arm/arm.c	(revision 110439)
+++ config/arm/arm.c	(working copy)
@@ -6827,14 +6827,14 @@ arm_reload_in_hi (rtx *operands)
       if (reg_equiv_mem[REGNO (ref)])
 	{
 	  ref = reg_equiv_mem[REGNO (ref)];
-	  base = find_replacement (&XEXP (ref, 0));
+	  base = XEXP (ref, 0);
 	}
       else
 	/* The slot is out of range, or was dressed up in a SUBREG.  */
 	base = reg_equiv_address[REGNO (ref)];
     }
   else
-    base = find_replacement (&XEXP (ref, 0));
+    base = XEXP (ref, 0);
 
   /* Handle the case where the address is too complex to be offset by 1.  */
   if (GET_CODE (base) == MINUS
@@ -6944,14 +6944,14 @@ arm_reload_out_hi (rtx *operands)
       if (reg_equiv_mem[REGNO (ref)])
 	{
 	  ref = reg_equiv_mem[REGNO (ref)];
-	  base = find_replacement (&XEXP (ref, 0));
+	  base = XEXP (ref, 0);
 	}
       else
 	/* The slot is out of range, or was dressed up in a SUBREG.  */
 	base = reg_equiv_address[REGNO (ref)];
     }
   else
-    base = find_replacement (&XEXP (ref, 0));
+    base = XEXP (ref, 0);
 
   scratch = gen_rtx_REG (SImode, REGNO (operands[2]));
 
Index: config/pa/pa.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L config/pa/pa.c	(revision 110439) -L config/pa/pa.c	(working copy) config/pa/.svn/text-base/pa.c.svn-base config/pa/pa.c
--- config/pa/pa.c	(revision 110439)
+++ config/pa/pa.c	(working copy)
@@ -1389,12 +1389,12 @@ emit_move_sequence (rtx *operands, enum 
     }
 
   if (scratch_reg && reload_in_progress && GET_CODE (operand0) == MEM
-      && ((tem = find_replacement (&XEXP (operand0, 0)))
+      && ((tem = XEXP (operand0, 0))
 	  != XEXP (operand0, 0)))
     operand0 = replace_equiv_address (operand0, tem);
 
   if (scratch_reg && reload_in_progress && GET_CODE (operand1) == MEM
-      && ((tem = find_replacement (&XEXP (operand1, 0)))
+      && ((tem = XEXP (operand1, 0))
 	  != XEXP (operand1, 0)))
     operand1 = replace_equiv_address (operand1, tem);
 
Index: reload1.c
===================================================================
/usr/bin/diff -p -d -F^( -u -L reload1.c	(revision 110439) -L reload1.c	(working copy) .svn/text-base/reload1.c.svn-base reload1.c
--- reload1.c	(revision 110439)
+++ reload1.c	(working copy)
@@ -3965,16 +3965,18 @@ reload_as_needed (int live_known)
 	      if (SMALL_REGISTER_CLASSES)
 		merge_assigned_reloads (insn);
 
+	      /* Substitute the chosen reload regs from reload_reg_rtx
+		 into the insn's body, or perhaps into information about
+		 the reloads that we are about to emit.
+		 It's for the sake of the latter that we do this before
+		 emitting the actual reload insns; this allows us to
+		 check reload insns for validity in gen_reload.  */
+	      subst_reloads (insn);
+
 	      /* Generate the insns to reload operands into or out of
 		 their reload regs.  */
 	      emit_reload_insns (chain);
 
-	      /* Substitute the chosen reload regs from reload_reg_rtx
-		 into the insn's body (or perhaps into the bodies of other
-		 load and store insn that we just made for reloading
-		 and that we moved the structure into).  */
-	      subst_reloads (insn);
-
 	      /* Adjust the exception region notes for loads and stores.  */
 	      if (flag_non_call_exceptions && !CALL_P (insn))
 		fixup_eh_region_note (insn, prev, next);
@@ -7646,12 +7648,7 @@ gen_reload (rtx out, rtx in, int opnum, 
 
      This entire process is made complex because reload will never
      process the insns we generate here and so we must ensure that
-     they will fit their constraints and also by the fact that parts of
-     IN might be being reloaded separately and replaced with spill registers.
-     Because of this, we are, in some sense, just guessing the right approach
-     here.  The one listed above seems to work.
-
-     ??? At some point, this whole thing needs to be rethought.  */
+     they will fit their constraints.  */
 
   if (GET_CODE (in) == PLUS
       && (REG_P (XEXP (in, 0))
@@ -7678,8 +7675,8 @@ gen_reload (rtx out, rtx in, int opnum, 
       rtx op0, op1, tem, insn;
       int code;
 
-      op0 = find_replacement (&XEXP (in, 0));
-      op1 = find_replacement (&XEXP (in, 1));
+      op0 = XEXP (in, 0);
+      op1 = XEXP (in, 1);
 
       /* Since constraint checking is strict, commutativity won't be
 	 checked, so we need to do that here to avoid spurious failure

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