2011-05-18 Bernd Schmidt <bernds@codesourcery.com>
Andrew Stubbs <ams@codesourcery.com>
gcc/
* combine.c (make_compound_operation): Remove 'static'.
* rtl.h (make_compound_operation): New prototype.
* simplify-rtx.c (simplify_unary_operation_1): Create a new
canonical form for widening multiplies.
@@ -427,7 +427,6 @@ static const_rtx expand_field_assignment (const_rtx);
static rtx make_extraction (enum machine_mode, rtx, HOST_WIDE_INT,
rtx, unsigned HOST_WIDE_INT, int, int, int);
static rtx extract_left_shift (rtx, int);
-static rtx make_compound_operation (rtx, enum rtx_code);
static int get_pos_from_mask (unsigned HOST_WIDE_INT,
unsigned HOST_WIDE_INT *);
static rtx canon_reg_for_combine (rtx, rtx);
@@ -7516,7 +7515,7 @@ extract_left_shift (rtx x, int count)
being kludges), it is MEM. When processing the arguments of a comparison
or a COMPARE against zero, it is COMPARE. */
-static rtx
+rtx
make_compound_operation (rtx x, enum rtx_code in_code)
{
enum rtx_code code = GET_CODE (x);
@@ -2372,6 +2372,7 @@ extern unsigned int extended_count (const_rtx, enum machine_mode, int);
extern rtx remove_death (unsigned int, rtx);
extern void dump_combine_stats (FILE *);
extern void dump_combine_total_stats (FILE *);
+extern rtx make_compound_operation (rtx, enum rtx_code);
/* In cfgcleanup.c */
extern void delete_dead_jumptables (void);
@@ -989,6 +989,8 @@ simplify_unary_operation_1 (enum rtx_code code, enum machine_mode mode, rtx op)
break;
case SIGN_EXTEND:
+ op = make_compound_operation (op, SET);
+
/* (sign_extend (truncate (minus (label_ref L1) (label_ref L2))))
becomes just the MINUS if its mode is MODE. This allows
folding switch statements on machines using casesi (such as
@@ -1000,6 +1002,23 @@ simplify_unary_operation_1 (enum rtx_code code, enum machine_mode mode, rtx op)
&& GET_CODE (XEXP (XEXP (op, 0), 1)) == LABEL_REF)
return XEXP (op, 0);
+ /* Extending a widening multiplication should be canonicalized to
+ a wider widening multiplication. */
+ if (GET_CODE (op) == MULT
+ && GET_CODE (XEXP (op, 0)) == SIGN_EXTEND
+ && GET_CODE (XEXP (op, 1)) == SIGN_EXTEND)
+ {
+ rtx op0 = XEXP (XEXP (op, 0), 0);
+ rtx op1 = XEXP (XEXP (op, 1), 0);
+ enum machine_mode op0_mode = GET_MODE (op0);
+ enum machine_mode op1_mode = GET_MODE (op1);
+ return simplify_gen_binary (MULT, mode,
+ simplify_gen_unary (SIGN_EXTEND, mode,
+ op0, op0_mode),
+ simplify_gen_unary (SIGN_EXTEND, mode,
+ op1, op1_mode));
+ }
+
/* Check for a sign extension of a subreg of a promoted
variable, where the promotion is sign-extended, and the
target mode is the same as the variable's promotion. */
@@ -1071,6 +1090,23 @@ simplify_unary_operation_1 (enum rtx_code code, enum machine_mode mode, rtx op)
&& GET_MODE_SIZE (mode) <= GET_MODE_SIZE (GET_MODE (XEXP (op, 0))))
return rtl_hooks.gen_lowpart_no_emit (mode, op);
+ /* Extending a widening multiplication should be canonicalized to
+ a wider widening multiplication. */
+ if (GET_CODE (op) == MULT
+ && GET_CODE (XEXP (op, 0)) == ZERO_EXTEND
+ && GET_CODE (XEXP (op, 1)) == ZERO_EXTEND)
+ {
+ rtx op0 = XEXP (XEXP (op, 0), 0);
+ rtx op1 = XEXP (XEXP (op, 1), 0);
+ enum machine_mode op0_mode = GET_MODE (op0);
+ enum machine_mode op1_mode = GET_MODE (op1);
+ return simplify_gen_binary (MULT, mode,
+ simplify_gen_unary (ZERO_EXTEND, mode,
+ op0, op0_mode),
+ simplify_gen_unary (ZERO_EXTEND, mode,
+ op1, op1_mode));
+ }
+
/* (zero_extend:M (zero_extend:N <X>)) is (zero_extend:M <X>). */
if (GET_CODE (op) == ZERO_EXTEND)
return simplify_gen_unary (ZERO_EXTEND, mode, XEXP (op, 0),