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]

[PATCH] Handle CONST in a few more places in simplify-rtx.c


Hi!

While looking at how simplify-rtx.c handles constants wrapped by
wrap_constant, I've noticed that simplify_unary_operation handles it well,
but binary/relational/subregs are not.

The following patch fixes that.

Bootstrapped/regtested on x86_64-linux and i686-linux with
--enable-checking=yes,rtl, ok for trunk?

2009-09-11  Jakub Jelinek  <jakub@redhat.com>

	* simplify-rtx.c (simplify_binary_operation): Look through CONST
	trueop[01].
	(simplify_binary_operation_1): For trueop[01] instead of op[01]
	where possible.
	(simplify_relational_operation): Look through CONST op[01].
	(simplify_subreg): Look through CONST op.

--- gcc/simplify-rtx.c.jj	2009-09-03 09:59:40.000000000 +0200
+++ gcc/simplify-rtx.c	2009-09-11 13:33:26.000000000 +0200
@@ -1642,6 +1642,10 @@ simplify_binary_operation (enum rtx_code
 
   trueop0 = avoid_constant_pool_reference (op0);
   trueop1 = avoid_constant_pool_reference (op1);
+  if (GET_CODE (trueop0) == CONST)
+    trueop0 = XEXP (trueop0, 0);
+  if (GET_CODE (trueop1) == CONST)
+    trueop1 = XEXP (trueop1, 0);
 
   tem = simplify_const_binary_operation (code, mode, trueop0, trueop1);
   if (tem)
@@ -1697,13 +1701,13 @@ simplify_binary_operation_1 (enum rtx_co
       if ((GET_CODE (op0) == CONST
 	   || GET_CODE (op0) == SYMBOL_REF
 	   || GET_CODE (op0) == LABEL_REF)
-	  && CONST_INT_P (op1))
-	return plus_constant (op0, INTVAL (op1));
+	  && CONST_INT_P (trueop1))
+	return plus_constant (op0, INTVAL (trueop1));
       else if ((GET_CODE (op1) == CONST
 		|| GET_CODE (op1) == SYMBOL_REF
 		|| GET_CODE (op1) == LABEL_REF)
-	       && CONST_INT_P (op0))
-	return plus_constant (op1, INTVAL (op0));
+	       && CONST_INT_P (trueop0))
+	return plus_constant (op1, INTVAL (trueop0));
 
       /* See if this is something like X * C - X or vice versa or
 	 if the multiplication is written as a shift.  If so, we can
@@ -1781,14 +1785,14 @@ simplify_binary_operation_1 (enum rtx_co
 	}
 
       /* (plus (xor X C1) C2) is (xor X (C1^C2)) if C2 is signbit.  */
-      if ((CONST_INT_P (op1)
-	   || GET_CODE (op1) == CONST_DOUBLE)
+      if ((CONST_INT_P (trueop1)
+	   || GET_CODE (trueop1) == CONST_DOUBLE)
 	  && GET_CODE (op0) == XOR
 	  && (CONST_INT_P (XEXP (op0, 1))
 	      || GET_CODE (XEXP (op0, 1)) == CONST_DOUBLE)
-	  && mode_signbit_p (mode, op1))
+	  && mode_signbit_p (mode, trueop1))
 	return simplify_gen_binary (XOR, mode, XEXP (op0, 0),
-				    simplify_gen_binary (XOR, mode, op1,
+				    simplify_gen_binary (XOR, mode, trueop1,
 							 XEXP (op0, 1)));
 
       /* Canonicalize (plus (mult (neg B) C) A) to (minus A (mult B C)).  */
@@ -3863,6 +3867,11 @@ simplify_relational_operation (enum rtx_
   if (cmp_mode == VOIDmode)
     cmp_mode = GET_MODE (op1);
 
+  if (GET_CODE (op0) == CONST)
+    op0 = XEXP (op0, 0);
+  if (GET_CODE (op1) == CONST)
+    op1 = XEXP (op1, 0);
+
   tem = simplify_const_relational_operation (code, cmp_mode, op0, op1);
   if (tem)
     {
@@ -5084,6 +5093,9 @@ simplify_subreg (enum machine_mode outer
   if (outermode == innermode && !byte)
     return op;
 
+  if (GET_CODE (op) == CONST)
+    op = XEXP (op, 0);
+
   if (CONST_INT_P (op)
       || GET_CODE (op) == CONST_DOUBLE
       || GET_CODE (op) == CONST_FIXED

	Jakub


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