The aim of this patch is to make rtx_costs for SETs closer to
insn_cost for SETs.  One visible effect on powerpc code is increased
if-conversion.

        * config/rs6000/rs6000.c (rs6000_rtx_costs): Reduce cost of SET
        operands.

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 76aedbfae6f..d455aa52427 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -21684,6 +21684,35 @@ rs6000_rtx_costs (rtx x, machine_mode mode, int 
outer_code,
        }
       return false;
 
+    case SET:
+      /* On entry the value in *TOTAL is the number of general purpose
+        regs being set, multiplied by COSTS_N_INSNS (1).  Handle
+        costing of set operands specially since in most cases we have
+        an instruction rather than just a piece of RTL and should
+        return a cost comparable to insn_cost.  That's a little
+        complicated because in some cases the cost of SET operands is
+        non-zero, see point 5 above and cost of PLUS for example, and
+        in others it is zero, for example for (set (reg) (reg)).
+        But (set (reg) (reg)) has the same insn_cost as
+        (set (reg) (plus (reg) (reg))).  Hack around this by
+        subtracting COSTS_N_INSNS (1) from the operand cost in cases
+        were we add at least COSTS_N_INSNS (1) for some operation.
+        However, don't do so for constants.  Constants might cost
+        more than zero when they require more than one instruction,
+        and we do want the cost of extra instructions.  */
+      {
+       rtx_code src_code = GET_CODE (SET_SRC (x));
+       if (src_code == CONST_INT
+           || src_code == CONST_DOUBLE
+           || src_code == CONST_WIDE_INT)
+         return false;
+       int set_cost = (rtx_cost (SET_SRC (x), mode, SET, 1, speed)
+                       + rtx_cost (SET_DEST (x), mode, SET, 0, speed));
+       if (set_cost >= COSTS_N_INSNS (1))
+         *total += set_cost - COSTS_N_INSNS (1);
+       return true;
+      }
+
     default:
       return false;
     }

Reply via email to