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]

Re: Canonicalising truncated shift counts


Eric Botcazou <ebotcazou@libertysurf.fr> writes:
>> I don't think that'd be the right approach.  It seems odd for
>> simplify_binary_operand to return null for a pair of operands
>> if simplify_gen_subreg would keep one operand and change the
>> value of the other.  This canonicalisation seems more in the
>> spirit of things like
>>
>>       (minus ... (const_int X)) -> (plus ... (const_int -X))
>>   and (mult ... (const_int 2<<X)) -> (ashift ... (const_int X))
>>
>> (especially the first).
>
> Agreed.  Patch is OK if you rename the label to 'canonicalize_*' and put the 
> new code either after the first affected case or the last affected case.

OK, thanks.  Here's what I installed after retesting on mipsisa32-elf.

Richard


gcc/
	* simplify-rtx.c (simplify_binary_operation_1): Canonicalize
	truncated shift counts.

Index: gcc/simplify-rtx.c
===================================================================
--- gcc/simplify-rtx.c	2007-10-07 10:43:25.000000000 +0100
+++ gcc/simplify-rtx.c	2007-10-07 10:44:37.000000000 +0100
@@ -2562,6 +2562,13 @@ simplify_binary_operation_1 (enum rtx_co
 	  && (unsigned HOST_WIDE_INT) INTVAL (trueop0) == GET_MODE_MASK (mode)
 	  && ! side_effects_p (op1))
 	return op0;
+    canonicalize_shift:
+      if (SHIFT_COUNT_TRUNCATED && GET_CODE (op1) == CONST_INT)
+	{
+	  val = INTVAL (op1) & (GET_MODE_BITSIZE (mode) - 1);
+	  if (val != INTVAL (op1))
+	    return simplify_gen_binary (code, mode, op0, GEN_INT (val));
+	}
       break;
 
     case ASHIFT:
@@ -2571,7 +2578,7 @@ simplify_binary_operation_1 (enum rtx_co
 	return op0;
       if (trueop0 == CONST0_RTX (mode) && ! side_effects_p (op1))
 	return op0;
-      break;
+      goto canonicalize_shift;
 
     case LSHIFTRT:
       if (trueop1 == CONST0_RTX (mode))
@@ -2593,7 +2600,7 @@ simplify_binary_operation_1 (enum rtx_co
 	    return simplify_gen_relational (EQ, mode, imode,
 					    XEXP (op0, 0), const0_rtx);
 	}
-      break;
+      goto canonicalize_shift;
 
     case SMIN:
       if (width <= HOST_BITS_PER_WIDE_INT


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