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]

Add a default case for simplify_replace_rtx


Ulrich pointed out that simplify_replace_rtx didn't handle rtxes
like UNSPEC and UNSPEC_VOLATILE, which caused an ICE after my
wrap_constant changes.  Rather than go with my original UNSPEC*
patch, I've followed Jakub's suggestion and added a fallback case
to simplify_replace_rtx.

Tested on x86_64-linux-gnu.  OK to install?

Richard


gcc/
	* simplify-rtx.c (simplify_replace_fn_rtx): Add a fallback case
	for rtxes that aren't handled specially.

Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c	2009-10-22 21:00:52.000000000 +0100
+++ gcc/simplify-rtx.c	2009-10-22 21:03:40.000000000 +0100
@@ -363,7 +363,10 @@ simplify_replace_fn_rtx (rtx x, const_rt
   enum rtx_code code = GET_CODE (x);
   enum machine_mode mode = GET_MODE (x);
   enum machine_mode op_mode;
-  rtx op0, op1, op2;
+  const char *fmt;
+  rtx op0, op1, op2, newx, op;
+  rtvec vec, newvec;
+  int i, j;
 
   /* If X is OLD_RTX, return FN (X, DATA), with a null FN.  Otherwise,
      if this is an expression, try to build a new expression, substituting
@@ -420,7 +423,6 @@ simplify_replace_fn_rtx (rtx x, const_rt
       return simplify_gen_ternary (code, mode, op_mode, op0, op1, op2);
 
     case RTX_EXTRA:
-      /* The only case we try to handle is a SUBREG.  */
       if (code == SUBREG)
 	{
 	  op0 = simplify_replace_fn_rtx (SUBREG_REG (x), old_rtx, fn, data);
@@ -459,7 +461,44 @@ simplify_replace_fn_rtx (rtx x, const_rt
     default:
       break;
     }
-  return x;
+
+  newx = x;
+  fmt = GET_RTX_FORMAT (code);
+  for (i = 0; fmt[i]; i++)
+    switch (fmt[i])
+      {
+      case 'E':
+	vec = XVEC (x, i);
+	newvec = XVEC (newx, i);
+	for (j = 0; j < GET_NUM_ELEM (vec); j++)
+	  {
+	    op = simplify_replace_fn_rtx (RTVEC_ELT (vec, j),
+					  old_rtx, fn, data);
+	    if (op != RTVEC_ELT (vec, j))
+	      {
+		if (newvec == vec)
+		  {
+		    newvec = shallow_copy_rtvec (vec);
+		    if (x == newx)
+		      newx = shallow_copy_rtx (x);
+		    XVEC (newx, i) = newvec;
+		  }
+		RTVEC_ELT (newvec, j) = op;
+	      }
+	  }
+	break;
+
+      case 'e':
+	op = simplify_replace_fn_rtx (XEXP (x, i), old_rtx, fn, data);
+	if (op != XEXP (x, i))
+	  {
+	    if (x == newx)
+	      newx = shallow_copy_rtx (x);
+	    XEXP (newx, i) = op;
+	  }
+	break;
+      }
+  return newx;
 }
 
 /* Replace all occurrences of OLD_RTX in X with NEW_RTX and try to simplify the


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