@@ -891,6 +891,7 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
if (set && REG_P (SET_SRC (set)))
{
rtx src = SET_SRC (set);
+ rtx dest = SET_DEST (set);
unsigned int regno = REGNO (src);
machine_mode mode = GET_MODE (src);
unsigned int i;
@@ -914,7 +915,7 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
/* If the destination is also a register, try to find a source
register in the same class. */
- if (REG_P (SET_DEST (set)))
+ if (REG_P (dest))
{
new_rtx = find_oldest_value_reg (REGNO_REG_CLASS (regno),
src, vd);
@@ -942,6 +943,20 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
mode, i, regno);
if (new_rtx != NULL_RTX)
{
+ /* Don't propagate for a more expensive reg-reg move. */
+ if (REG_P (dest))
+ {
+ enum reg_class from = REGNO_REG_CLASS (regno);
+ enum reg_class to = REGNO_REG_CLASS (REGNO (dest));
+ enum reg_class new_from = REGNO_REG_CLASS (i);
+ unsigned int original_cost
+ = targetm.register_move_cost (mode, from, to);
+ unsigned int after_cost
+ = targetm.register_move_cost (mode, new_from, to);
+ if (after_cost > original_cost)
+ goto no_move_special_case;
+ }
+
if (validate_change (insn, &SET_SRC (set), new_rtx, 0))
{
ORIGINAL_REGNO (new_rtx) = ORIGINAL_REGNO (src);
new file mode 100644
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx2 -O2 -fdump-rtl-cprop_hardreg-details" } */
+/* { dg-final { scan-rtl-dump-not {replaced reg [0-9]* with [0-9]*} "cprop_hardreg" } } */
+
+#include<stdint.h>
+int test (uint8_t *p, uint32_t t[1][1], int n) {
+
+ int sum = 0;
+ uint32_t a0;
+ for (int i = 0; i < 4; i++, p++)
+ t[i][0] = p[0];
+
+ for (int i = 0; i < 4; i++) {
+ {
+ int t0 = t[0][i] + t[0][i];
+ a0 = t0;
+ };
+ sum += a0;
+ }
+ return (((uint16_t)sum) + ((uint32_t)sum >> 16)) >> 1;
+}
+