Slight cost adjustment in SLSR

Message ID b175881b-d2fc-190a-fc6c-71a90a6c4e76@linux.vnet.ibm.com
State New
Headers show
Series
  • Slight cost adjustment in SLSR
Related show

Commit Message

Bill Schmidt Dec. 14, 2017, 7:12 p.m.
Hi,

While looking at PR83253, I noticed that the cost model for MULT_EXPR
replacement can be improved.  Right now we use mult_by_coeff_cost to
determine the value of the possible replacement, but we use mul_cost
to determine the savings from removing the original expression.  This
overcounts the savings when the expression being replaced is a multiply
by a constant.  In such cases we can again use mult_by_coeff_cost to
determine the savings.  This will reduce the chance of making an
unprofitable replacement.

Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no
regressions.  Is this okay for trunk?

Thanks,
Bill


2017-12-14  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	* gimple-ssa-strength-reduction.c (analyze_increments):
	Distinguish replacement costs for constant strides from those for
	unknown strides.

Comments

Richard Biener Dec. 14, 2017, 7:34 p.m. | #1
On December 14, 2017 8:12:36 PM GMT+01:00, Bill Schmidt <wschmidt@linux.vnet.ibm.com> wrote:
>Hi,

>

>While looking at PR83253, I noticed that the cost model for MULT_EXPR

>replacement can be improved.  Right now we use mult_by_coeff_cost to

>determine the value of the possible replacement, but we use mul_cost

>to determine the savings from removing the original expression.  This

>overcounts the savings when the expression being replaced is a multiply

>by a constant.  In such cases we can again use mult_by_coeff_cost to

>determine the savings.  This will reduce the chance of making an

>unprofitable replacement.

>

>Bootstrapped and tested on powerpc64le-unknown-linux-gnu with no

>regressions.  Is this okay for trunk?


OK. 

Richard. 

>Thanks,

>Bill

>

>

>2017-12-14  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

>

>	* gimple-ssa-strength-reduction.c (analyze_increments):

>	Distinguish replacement costs for constant strides from those for

>	unknown strides.

>

>

>Index: gcc/gimple-ssa-strength-reduction.c

>===================================================================

>--- gcc/gimple-ssa-strength-reduction.c	(revision 255588)

>+++ gcc/gimple-ssa-strength-reduction.c	(working copy)

>@@ -3083,7 +3083,17 @@ analyze_increments (slsr_cand_t first_dep,

>machine

>       else if (first_dep->kind == CAND_MULT)

> 	{

> 	  int cost = mult_by_coeff_cost (incr, mode, speed);

>-	  int repl_savings = mul_cost (speed, mode) - add_cost (speed, mode);

>+	  int repl_savings;

>+

>+	  if (tree_fits_shwi_p (first_dep->stride))

>+	    {

>+	      HOST_WIDE_INT hwi_stride = tree_to_shwi (first_dep->stride);

>+	      repl_savings = mult_by_coeff_cost (hwi_stride, mode, speed);

>+	    }

>+	  else

>+	    repl_savings = mul_cost (speed, mode);

>+	  repl_savings -= add_cost (speed, mode);

>+

> 	  if (speed)

> 	    cost = lowest_cost_path (cost, repl_savings, first_dep,

> 				     incr_vec[i].incr, COUNT_PHIS);

Patch

Index: gcc/gimple-ssa-strength-reduction.c
===================================================================
--- gcc/gimple-ssa-strength-reduction.c	(revision 255588)
+++ gcc/gimple-ssa-strength-reduction.c	(working copy)
@@ -3083,7 +3083,17 @@  analyze_increments (slsr_cand_t first_dep, machine
       else if (first_dep->kind == CAND_MULT)
 	{
 	  int cost = mult_by_coeff_cost (incr, mode, speed);
-	  int repl_savings = mul_cost (speed, mode) - add_cost (speed, mode);
+	  int repl_savings;
+
+	  if (tree_fits_shwi_p (first_dep->stride))
+	    {
+	      HOST_WIDE_INT hwi_stride = tree_to_shwi (first_dep->stride);
+	      repl_savings = mult_by_coeff_cost (hwi_stride, mode, speed);
+	    }
+	  else
+	    repl_savings = mul_cost (speed, mode);
+	  repl_savings -= add_cost (speed, mode);
+
 	  if (speed)
 	    cost = lowest_cost_path (cost, repl_savings, first_dep,
 				     incr_vec[i].incr, COUNT_PHIS);