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]

Make fold_rtx in cse.c verbose


Hi,

The attached patch makes fold_rtx dump what it is returing: a new
rtx, or the same as the input.  I've been using this patch to find
cases where cse.c is still doing something useful.  Would this be
acceptable for mainline?
Bootstrapped on x86_64-unknown-linux-gnu.

Gr.
Steven

Index: cse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cse.c,v
retrieving revision 1.346
diff -u -3 -p -r1.346 cse.c
--- cse.c	6 Mar 2005 05:21:10 -0000	1.346
+++ cse.c	6 Mar 2005 15:43:09 -0000
@@ -3563,6 +3563,15 @@ fold_rtx_mem (rtx x, rtx insn)
    INSN is the insn that we may be modifying.  If it is 0, make a copy
    of X before modifying it.  */
 
+#define RETURN(X) { new = (X); goto report_and_return; }
+
+#define INDENT(F,SPACE) do {			\
+    int __i;					\
+    int __end = (SPACE);			\
+    for (__i = 0; __i < __end; __i++)		\
+     fputc (' ', (F));				\
+  } while (0)
+
 static rtx
 fold_rtx (rtx x, rtx insn)
 {
@@ -3570,10 +3579,14 @@ fold_rtx (rtx x, rtx insn)
   enum machine_mode mode;
   const char *fmt;
   int i;
+  rtx orig_x = x;
   rtx new = 0;
   int copied = 0;
   int must_swap = 0;
 
+  /* Counter for many times have we called ourselve recursively.  */
+  static int nesting_level = 0;
+
   /* Folded equivalents of first two operands of X.  */
   rtx folded_arg0;
   rtx folded_arg1;
@@ -3588,8 +3601,18 @@ fold_rtx (rtx x, rtx insn)
      extends.  */
   enum machine_mode mode_arg0;
 
+  nesting_level++;
+
+  if (dump_file)
+    {
+      INDENT (dump_file, (nesting_level - 1) * 2);
+      fprintf (dump_file, "Trying to fold rtx:\n");
+      INDENT (dump_file, (nesting_level - 1) * 2);
+      print_rtl_single (dump_file, x);
+    }
+
   if (x == 0)
-    return x;
+    RETURN (x);
 
   mode = GET_MODE (x);
   code = GET_CODE (x);
@@ -3607,15 +3630,15 @@ fold_rtx (rtx x, rtx insn)
 	 since they are used only for lists of args
 	 in a function call's REG_EQUAL note.  */
     case EXPR_LIST:
-      return x;
+      RETURN (x);
 
 #ifdef HAVE_cc0
     case CC0:
-      return prev_insn_cc0;
+      RETURN (prev_insn_cc0);
 #endif
 
     case SUBREG:
-      return fold_rtx_subreg (x, insn);
+      RETURN (fold_rtx_subreg (x, insn));
 
     case NOT:
     case NEG:
@@ -3623,16 +3646,16 @@ fold_rtx (rtx x, rtx insn)
 	 If so, (NOT Y) simplifies to Z.  Similarly for NEG.  */
       new = lookup_as_function (XEXP (x, 0), code);
       if (new)
-	return fold_rtx (copy_rtx (XEXP (new, 0)), insn);
+	RETURN (fold_rtx (copy_rtx (XEXP (new, 0)), insn));
       break;
 
     case MEM:
-      return fold_rtx_mem (x, insn);
+      RETURN (fold_rtx_mem (x, insn));
 
 #ifdef NO_FUNCTION_CSE
     case CALL:
       if (CONSTANT_P (XEXP (XEXP (x, 0), 0)))
-	return x;
+	RETURN (x);
       break;
 #endif
 
@@ -3931,9 +3954,9 @@ fold_rtx (rtx x, rtx insn)
 		  && nonzero_address_p (folded_arg0))
 		{
 		  if (code == EQ)
-		    return false_rtx;
-		  else if (code == NE)
-		    return true_rtx;
+		    RETURN (false_rtx);
+		  if (code == NE)
+		    RETURN (true_rtx);
 		}
 
 	      /* See if the two operands are the same.  */
@@ -3953,16 +3976,20 @@ fold_rtx (rtx x, rtx insn)
 		{
 		  /* Sadly two equal NaNs are not equivalent.  */
 		  if (!HONOR_NANS (mode_arg0))
-		    return ((code == EQ || code == LE || code == GE
-			     || code == LEU || code == GEU || code == UNEQ
-			     || code == UNLE || code == UNGE
-			     || code == ORDERED)
-			    ? true_rtx : false_rtx);
+		    {
+		      new = ((code == EQ || code == LE || code == GE
+			      || code == LEU || code == GEU || code == UNEQ
+			      || code == UNLE || code == UNGE
+			      || code == ORDERED)
+			     ? true_rtx : false_rtx);
+		      RETURN (new);
+		    }
+
 		  /* Take care for the FP compares we can resolve.  */
 		  if (code == UNEQ || code == UNLE || code == UNGE)
-		    return true_rtx;
+		    RETURN (true_rtx);
 		  if (code == LTGT || code == LT || code == GT)
-		    return false_rtx;
+		    RETURN (false_rtx);
 		}
 
 	      /* If FOLDED_ARG0 is a register, see if the comparison we are
@@ -3986,8 +4013,11 @@ fold_rtx (rtx x, rtx insn)
 						  const_arg1))
 			      || (REG_P (folded_arg1)
 				  && (REG_QTY (REGNO (folded_arg1)) == ent->comparison_qty))))
-			return (comparison_dominates_p (ent->comparison_code, code)
-				? true_rtx : false_rtx);
+			{
+			  new = (comparison_dominates_p (ent->comparison_code, code)
+				 ? true_rtx : false_rtx);
+			  RETURN (new);
+			}
 		    }
 		}
 	    }
@@ -4025,16 +4055,18 @@ fold_rtx (rtx x, rtx insn)
 	      switch (code)
 		{
 		case EQ:
-		  return false_rtx;
+		  RETURN (false_rtx);
 		case NE:
-		  return true_rtx;
-		case LT:  case LE:
+		  RETURN (true_rtx);
+		case LT:
+		case LE:
 		  if (has_sign)
-		    return true_rtx;
+		    RETURN (true_rtx);
 		  break;
-		case GT:  case GE:
+		case GT:
+		case GE:
 		  if (has_sign)
-		    return false_rtx;
+		    RETURN (false_rtx);
 		  break;
 		default:
 		  break;
@@ -4066,7 +4098,7 @@ fold_rtx (rtx x, rtx insn)
 
 	      if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF
 		  && XEXP (XEXP (y, 1), 0) == XEXP (const_arg1, 0))
-		return XEXP (y, 0);
+		RETURN (XEXP (y, 0));
 
 	      /* Now try for a CONST of a MINUS like the above.  */
 	      if ((y = (GET_CODE (folded_arg0) == CONST ? folded_arg0
@@ -4074,7 +4106,7 @@ fold_rtx (rtx x, rtx insn)
 		  && GET_CODE (XEXP (y, 0)) == MINUS
 		  && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF
 		  && XEXP (XEXP (XEXP (y, 0), 1), 0) == XEXP (const_arg1, 0))
-		return XEXP (XEXP (y, 0), 0);
+		RETURN (XEXP (XEXP (y, 0), 0));
 	    }
 
 	  /* Likewise if the operands are in the other order.  */
@@ -4086,7 +4118,7 @@ fold_rtx (rtx x, rtx insn)
 
 	      if (y != 0 && GET_CODE (XEXP (y, 1)) == LABEL_REF
 		  && XEXP (XEXP (y, 1), 0) == XEXP (const_arg0, 0))
-		return XEXP (y, 0);
+		RETURN (XEXP (y, 0));
 
 	      /* Now try for a CONST of a MINUS like the above.  */
 	      if ((y = (GET_CODE (folded_arg1) == CONST ? folded_arg1
@@ -4094,7 +4126,7 @@ fold_rtx (rtx x, rtx insn)
 		  && GET_CODE (XEXP (y, 0)) == MINUS
 		  && GET_CODE (XEXP (XEXP (y, 0), 1)) == LABEL_REF
 		  && XEXP (XEXP (XEXP (y, 0), 1), 0) == XEXP (const_arg0, 0))
-		return XEXP (XEXP (y, 0), 0);
+		RETURN (XEXP (XEXP (y, 0), 0));
 	    }
 
 	  /* If second operand is a register equivalent to a negative
@@ -4127,8 +4159,8 @@ fold_rtx (rtx x, rtx insn)
 	      if (p)
 		for (p = p->first_same_value; p; p = p->next_same_value)
 		  if (REG_P (p->exp))
-		    return simplify_gen_binary (MINUS, mode, folded_arg0,
-						canon_reg (p->exp, NULL_RTX));
+		    RETURN (simplify_gen_binary (MINUS, mode, folded_arg0,
+						 canon_reg (p->exp, NULL_RTX)));
 	    }
 	  goto from_plus;
 
@@ -4139,9 +4171,9 @@ fold_rtx (rtx x, rtx insn)
 	    {
 	      rtx y = lookup_as_function (XEXP (x, 0), PLUS);
 	      if (y && GET_CODE (XEXP (y, 1)) == CONST_INT)
-		return fold_rtx (plus_constant (copy_rtx (y),
-						-INTVAL (const_arg1)),
-				 NULL_RTX);
+		RETURN (fold_rtx (plus_constant (copy_rtx (y),
+						 -INTVAL (const_arg1)),
+				  NULL_RTX));
 	    }
 
 	  /* Fall through.  */
@@ -4233,11 +4265,12 @@ fold_rtx (rtx x, rtx insn)
 	      if (! reg_mentioned_p (folded_arg0, y))
 		y = fold_rtx (y, insn);
 
-	      return simplify_gen_binary (code, mode, y, new_const);
+	      RETURN (simplify_gen_binary (code, mode, y, new_const));
 	    }
 	  break;
 
-	case DIV:       case UDIV:
+	case DIV:
+	case UDIV:
 	  /* ??? The associative optimization performed immediately above is
 	     also possible for DIV and UDIV using associate_code of MULT.
 	     However, we would need extra code to verify that the
@@ -4259,7 +4292,7 @@ fold_rtx (rtx x, rtx insn)
       if (code == LO_SUM && const_arg0 != 0
 	  && GET_CODE (const_arg0) == HIGH
 	  && rtx_equal_p (XEXP (const_arg0, 0), const_arg1))
-	return const_arg1;
+	RETURN (const_arg1);
       break;
 
     case RTX_TERNARY:
@@ -4274,6 +4307,28 @@ fold_rtx (rtx x, rtx insn)
       break;
     }
 
+report_and_return:
+  if (dump_file)
+    {
+      if (new && new != orig_x)
+	{
+	  INDENT (dump_file, (nesting_level - 1) * 2);
+	  fprintf (dump_file, "Returning new rtx:\n");
+	  INDENT (dump_file, (nesting_level - 1) * 2);
+	  print_rtl_single (dump_file, new);
+	  if (nesting_level == 1)
+	    fprintf (dump_file, "\n");
+	}
+      else
+	{
+	  INDENT (dump_file, (nesting_level - 1) * 2);
+	  fprintf (dump_file, "Returning X unchanged.\n");
+	  if (nesting_level == 1)
+	    fprintf (dump_file, "\n");
+	}
+    }
+  nesting_level--;
+
   return new ? new : x;
 }
 


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