Patchwork Add a set_src_cost wrapper function

login
register
mail settings
Submitter Richard Sandiford
Date Aug. 18, 2011, 12:40 p.m.
Message ID <m3ei0iriy0.fsf@richards-thinkpad.stglab.manchester.uk.ibm.com>
Download mbox | patch
Permalink /patch/110516/
State New
Headers show

Comments

Richard Sandiford - Aug. 18, 2011, 12:40 p.m.
Richard Guenther <richard.guenther@gmail.com> writes:
> On Mon, Aug 15, 2011 at 4:56 PM, Richard Sandiford
> <richard.sandiford@linaro.org> wrote:
>> I'm about to post a patch that adds an extra parameter to rtx_cost.
>> Since most callers to rtx_cost are for SET_SRCs, it seemed a shame to
>> have to add an extra boiler-plate parameter to each of them.  The patch
>> below therefore adds a set_src_cost wrapper for this common case.
>>
>> Tested on x86_64-linux-gnu.  Also tested by compiling cc1 for:
>>
>>    avr-rtems bfin-elf mips64-linux-gnu x86_64-linux-gnu
>>
>> and making sure that there were (a) no new warnings and (b) no differences
>> in -Os or -O2 output for gcc.c-torture and gcc.dg.  OK to install?
>
> Ok.

Thanks.  As explained in:

   http://gcc.gnu.org/ml/gcc/2011-08/msg00306.html

I later realised that some of these calls aren't actually testing the
set_src at all, so I ended up applying the patch below for those cases,
but keeping the rest of the patch as-is.

This patch seemed like an obvious adjustment to the approved one,
or within bits I can self-approve, so applied after testing on
arm-linux-gnueabi and x86_64-linux-gnu.

Richard


gcc/
	* rtl.h (set_rtx_cost, get_full_set_rtx_cost): New functions.
	* auto-inc-dec.c (attempt_change): Use set_rtx_cost.
	* cfgloopanal.c (seq_cost): Likewise.
	* loop-invariant.c (create_new_invariant): Likewise.
	* postreload.c (move2add_use_add2_insn, move2add_use_add3_insn)
	(reload_cse_move2add): Use get_full_set_rtx_cost.

Patch

Index: gcc/rtl.h
===================================================================
--- gcc/rtl.h	2011-08-17 14:10:30.000000000 +0100
+++ gcc/rtl.h	2011-08-18 10:54:42.610246787 +0100
@@ -1217,6 +1217,24 @@  extern bool constant_pool_constant_p (rt
 extern bool truncated_to_mode (enum machine_mode, const_rtx);
 extern int low_bitmask_len (enum machine_mode, unsigned HOST_WIDE_INT);
 
+#ifndef GENERATOR_FILE
+/* Return the cost of SET X.  SPEED_P is true if optimizing for speed
+   rather than size.  */
+
+static inline int
+set_rtx_cost (rtx x, bool speed_p)
+{
+  return rtx_cost (x, INSN, speed_p);
+}
+
+/* Like set_rtx_cost, but return both the speed and size costs in C.  */
+
+static inline void
+get_full_set_rtx_cost (rtx x, struct full_rtx_costs *c)
+{
+  get_full_rtx_cost (x, INSN, c);
+}
+#endif
 
 /* 1 if RTX is a subreg containing a reg that is already known to be
    sign- or zero-extended from the mode of the subreg to the mode of
Index: gcc/auto-inc-dec.c
===================================================================
--- gcc/auto-inc-dec.c	2011-08-17 14:10:30.000000000 +0100
+++ gcc/auto-inc-dec.c	2011-08-18 10:54:42.639246679 +0100
@@ -484,7 +484,7 @@  attempt_change (rtx new_addr, rtx inc_re
   XEXP (mem_tmp, 0) = new_addr;
 
   old_cost = (rtx_cost (mem, SET, speed)
-	      + rtx_cost (PATTERN (inc_insn.insn), SET, speed));
+	      + set_rtx_cost (PATTERN (inc_insn.insn), speed));
   new_cost = rtx_cost (mem_tmp, SET, speed);
 
   /* The first item of business is to see if this is profitable.  */
Index: gcc/cfgloopanal.c
===================================================================
--- gcc/cfgloopanal.c	2011-08-17 14:10:30.000000000 +0100
+++ gcc/cfgloopanal.c	2011-08-17 14:32:47.993232649 +0100
@@ -314,7 +314,7 @@  seq_cost (const_rtx seq, bool speed)
     {
       set = single_set (seq);
       if (set)
-	cost += rtx_cost (set, SET, speed);
+	cost += set_rtx_cost (set, speed);
       else
 	cost++;
     }
Index: gcc/loop-invariant.c
===================================================================
--- gcc/loop-invariant.c	2011-08-17 14:10:30.000000000 +0100
+++ gcc/loop-invariant.c	2011-08-18 10:54:42.639246679 +0100
@@ -704,7 +704,7 @@  create_new_invariant (struct def *def, r
      the loop.  Otherwise we save only cost of the computation.  */
   if (def)
     {
-      inv->cost = rtx_cost (set, SET, speed);
+      inv->cost = set_rtx_cost (set, speed);
       /* ??? Try to determine cheapness of address computation.  Unfortunately
          the address cost is only a relative measure, we can't really compare
 	 it with any absolute number, but only with other address costs.
Index: gcc/postreload.c
===================================================================
--- gcc/postreload.c	2011-08-17 14:10:30.000000000 +0100
+++ gcc/postreload.c	2011-08-18 10:54:42.638246684 +0100
@@ -1683,9 +1683,9 @@  move2add_use_add2_insn (rtx reg, rtx sym
       struct full_rtx_costs oldcst, newcst;
       rtx tem = gen_rtx_PLUS (GET_MODE (reg), reg, new_src);
 
-      get_full_rtx_cost (pat, SET, &oldcst);
+      get_full_set_rtx_cost (pat, &oldcst);
       SET_SRC (pat) = tem;
-      get_full_rtx_cost (pat, SET, &newcst);
+      get_full_set_rtx_cost (pat, &newcst);
       SET_SRC (pat) = src;
 
       if (costs_lt_p (&newcst, &oldcst, speed)
@@ -1752,7 +1752,7 @@  move2add_use_add3_insn (rtx reg, rtx sym
   rtx plus_expr;
 
   init_costs_to_max (&mincst);
-  get_full_rtx_cost (pat, SET, &oldcst);
+  get_full_set_rtx_cost (pat, &oldcst);
 
   plus_expr = gen_rtx_PLUS (GET_MODE (reg), reg, const0_rtx);
   SET_SRC (pat) = plus_expr;
@@ -1781,7 +1781,7 @@  move2add_use_add3_insn (rtx reg, rtx sym
 	else
 	  {
 	    XEXP (plus_expr, 1) = new_src;
-	    get_full_rtx_cost (pat, SET, &newcst);
+	    get_full_set_rtx_cost (pat, &newcst);
 
 	    if (costs_lt_p (&newcst, &mincst, speed))
 	      {
@@ -1934,7 +1934,7 @@  reload_cse_move2add (rtx first)
 			  struct full_rtx_costs oldcst, newcst;
 			  rtx tem = gen_rtx_PLUS (GET_MODE (reg), reg, new_src);
 
-			  get_full_rtx_cost (set, SET, &oldcst);
+			  get_full_set_rtx_cost (set, &oldcst);
 			  SET_SRC (set) = tem;
 			  get_full_rtx_cost (tem, SET, &newcst);
 			  SET_SRC (set) = old_src;