Re: [PATCH 2/5] Replace insn_rtx_cost with insn_cost and pattern_cost

2017-08-02 Thread Jeff Law
On 07/31/2017 05:25 PM, Segher Boessenkool wrote:
> This renames insn_rtx_cost to pattern cost, and adds a new function
> insn_cost that takes an rtx_insn * instead of an instruction pattern
> as input.  It uses the latter function anywhere an instruction is
> readily available (instead of just an instruction pattern).
> 
> The actual implementation of insn_cost just calls pattern_cost on
> the pattern of the instruction; no functional change yet.
> 
> ---
>  gcc/cfgrtl.c  |  7 +++
>  gcc/combine.c | 17 -
>  gcc/dse.c |  2 +-
>  gcc/ifcvt.c   | 12 ++--
>  gcc/rtl.h |  3 ++-
>  gcc/rtlanal.c | 13 +++--
>  6 files changed, 31 insertions(+), 23 deletions(-)
Also looks good to me to go in once you've got a ChangeLog.

jeff



[PATCH 2/5] Replace insn_rtx_cost with insn_cost and pattern_cost

2017-07-31 Thread Segher Boessenkool
This renames insn_rtx_cost to pattern cost, and adds a new function
insn_cost that takes an rtx_insn * instead of an instruction pattern
as input.  It uses the latter function anywhere an instruction is
readily available (instead of just an instruction pattern).

The actual implementation of insn_cost just calls pattern_cost on
the pattern of the instruction; no functional change yet.

---
 gcc/cfgrtl.c  |  7 +++
 gcc/combine.c | 17 -
 gcc/dse.c |  2 +-
 gcc/ifcvt.c   | 12 ++--
 gcc/rtl.h |  3 ++-
 gcc/rtlanal.c | 13 +++--
 6 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index 6ef47b7..739d1bb 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -5039,14 +5039,13 @@ rtl_account_profile_record (basic_block bb, int 
after_pass,
   FOR_BB_INSNS (bb, insn)
 if (INSN_P (insn))
   {
-   record->size[after_pass]
- += insn_rtx_cost (PATTERN (insn), false);
+   record->size[after_pass] += insn_cost (insn, false);
if (bb->count.initialized_p ())
  record->time[after_pass]
-   += insn_rtx_cost (PATTERN (insn), true) * bb->count.to_gcov_type ();
+   += insn_cost (insn, true) * bb->count.to_gcov_type ();
else if (profile_status_for_fn (cfun) == PROFILE_GUESSED)
  record->time[after_pass]
-   += insn_rtx_cost (PATTERN (insn), true) * bb->frequency;
+   += insn_cost (insn, true) * bb->frequency;
   }
 }
 
diff --git a/gcc/combine.c b/gcc/combine.c
index c5200db..aadd328 100644
--- a/gcc/combine.c
+++ b/gcc/combine.c
@@ -311,7 +311,7 @@ static bool optimize_this_for_speed_p;
 
 static int max_uid_known;
 
-/* The following array records the insn_rtx_cost for every insn
+/* The following array records the insn_cost for every insn
in the instruction stream.  */
 
 static int *uid_insn_cost;
@@ -841,7 +841,7 @@ do_SUBST_LINK (struct insn_link **into, struct insn_link 
*newval)
 #define SUBST_LINK(oldval, newval) do_SUBST_LINK (, newval)
 
 /* Subroutine of try_combine.  Determine whether the replacement patterns
-   NEWPAT, NEWI2PAT and NEWOTHERPAT are cheaper according to insn_rtx_cost
+   NEWPAT, NEWI2PAT and NEWOTHERPAT are cheaper according to insn_cost
than the original sequence I0, I1, I2, I3 and undobuf.other_insn.  Note
that I0, I1 and/or NEWI2PAT may be NULL_RTX.  Similarly, NEWOTHERPAT and
undobuf.other_insn may also both be NULL_RTX.  Return false if the cost
@@ -888,11 +888,11 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, 
rtx_insn *i2, rtx_insn *i3,
 old_cost -= i1_cost;
 
 
-  /* Calculate the replacement insn_rtx_costs.  */
-  new_i3_cost = insn_rtx_cost (newpat, optimize_this_for_speed_p);
+  /* Calculate the replacement pattern_costs.  */
+  new_i3_cost = pattern_cost (newpat, optimize_this_for_speed_p);
   if (newi2pat)
 {
-  new_i2_cost = insn_rtx_cost (newi2pat, optimize_this_for_speed_p);
+  new_i2_cost = pattern_cost (newi2pat, optimize_this_for_speed_p);
   new_cost = (new_i2_cost > 0 && new_i3_cost > 0)
 ? new_i2_cost + new_i3_cost : 0;
 }
@@ -907,7 +907,7 @@ combine_validate_cost (rtx_insn *i0, rtx_insn *i1, rtx_insn 
*i2, rtx_insn *i3,
   int old_other_cost, new_other_cost;
 
   old_other_cost = INSN_COST (undobuf.other_insn);
-  new_other_cost = insn_rtx_cost (newotherpat, optimize_this_for_speed_p);
+  new_other_cost = pattern_cost (newotherpat, optimize_this_for_speed_p);
   if (old_other_cost > 0 && new_other_cost > 0)
{
  old_cost += old_other_cost;
@@ -1208,10 +1208,9 @@ combine_instructions (rtx_insn *f, unsigned int nregs)
  set_nonzero_bits_and_sign_copies (XEXP (links, 0), NULL_RTX,
insn);
 
-   /* Record the current insn_rtx_cost of this instruction.  */
+   /* Record the current insn_cost of this instruction.  */
if (NONJUMP_INSN_P (insn))
- INSN_COST (insn) = insn_rtx_cost (PATTERN (insn),
-   optimize_this_for_speed_p);
+ INSN_COST (insn) = insn_cost (insn, optimize_this_for_speed_p);
if (dump_file)
  {
fprintf (dump_file, "insn_cost %d for ", INSN_COST (insn));
diff --git a/gcc/dse.c b/gcc/dse.c
index f87dd50..9ffb696 100644
--- a/gcc/dse.c
+++ b/gcc/dse.c
@@ -1650,7 +1650,7 @@ find_shift_sequence (int access_size,
   cost = 0;
   for (insn = shift_seq; insn != NULL_RTX; insn = NEXT_INSN (insn))
if (INSN_P (insn))
- cost += insn_rtx_cost (PATTERN (insn), speed);
+ cost += insn_cost (insn, speed);
 
   /* The computation up to here is essentially independent
 of the arguments and could be precomputed.  It may
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 46a13c4..7de287f 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -121,7 +121,7 @@ count_bb_insns (const_basic_block bb)