diff mbox series

Improve ivopts handling of forced scales

Message ID 87y3nnnx7f.fsf@linaro.org
State Accepted
Commit 4d93060263ecf25f6324dbc5d07bbd79166cb2a3
Headers show
Series Improve ivopts handling of forced scales | expand

Commit Message

Richard Sandiford Nov. 3, 2017, 4:28 p.m. UTC
This patch improves the ivopts address cost calculcation for modes
in which an index must be scaled rather than unscaled.  Previously
we would only try the scaled form if the unscaled form was valid.

Many of the SVE tests rely on this when matching scaled indices.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu.
OK to install?

Richard


2017-11-03  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/
	* tree-ssa-loop-ivopts.c (get_address_cost): Try using a
	scaled index even if the unscaled address was invalid.
	Don't increase the complexity of using a scale in that case.

Comments

Bin.Cheng Nov. 6, 2017, 10:40 a.m. UTC | #1
On Fri, Nov 3, 2017 at 4:28 PM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> This patch improves the ivopts address cost calculcation for modes

> in which an index must be scaled rather than unscaled.  Previously

> we would only try the scaled form if the unscaled form was valid.

>

> Many of the SVE tests rely on this when matching scaled indices.

>

> Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64-linux-gnu.

> OK to install?

OK.

Thanks,
bin
>

> Richard

>

>

> 2017-11-03  Richard Sandiford  <richard.sandiford@linaro.org>

>             Alan Hayward  <alan.hayward@arm.com>

>             David Sherwood  <david.sherwood@arm.com>

>

> gcc/

>         * tree-ssa-loop-ivopts.c (get_address_cost): Try using a

>         scaled index even if the unscaled address was invalid.

>         Don't increase the complexity of using a scale in that case.

>

> Index: gcc/tree-ssa-loop-ivopts.c

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

> --- gcc/tree-ssa-loop-ivopts.c  2017-11-03 12:20:07.041206480 +0000

> +++ gcc/tree-ssa-loop-ivopts.c  2017-11-03 12:20:07.193201997 +0000

> @@ -4333,18 +4333,25 @@ get_address_cost (struct ivopts_data *da

>    machine_mode addr_mode = TYPE_MODE (type);

>    machine_mode mem_mode = TYPE_MODE (TREE_TYPE (*use->op_p));

>    addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (use->iv->base));

> +  /* Only true if ratio != 1.  */

> +  bool ok_with_ratio_p = false;

> +  bool ok_without_ratio_p = false;

>

>    if (!aff_combination_const_p (aff_inv))

>      {

>        parts.index = integer_one_node;

>        /* Addressing mode "base + index".  */

> -      if (valid_mem_ref_p (mem_mode, as, &parts))

> +      ok_without_ratio_p = valid_mem_ref_p (mem_mode, as, &parts);

> +      if (ratio != 1)

>         {

>           parts.step = wide_int_to_tree (type, ratio);

>           /* Addressing mode "base + index << scale".  */

> -         if (ratio != 1 && !valid_mem_ref_p (mem_mode, as, &parts))

> +         ok_with_ratio_p = valid_mem_ref_p (mem_mode, as, &parts);

> +         if (!ok_with_ratio_p)

>             parts.step = NULL_TREE;

> -

> +       }

> +      if (ok_with_ratio_p || ok_without_ratio_p)

> +       {

>           if (maybe_nonzero (aff_inv->offset))

>             {

>               parts.offset = wide_int_to_tree (sizetype, aff_inv->offset);

> @@ -4444,7 +4451,9 @@ get_address_cost (struct ivopts_data *da

>

>    if (parts.symbol != NULL_TREE)

>      cost.complexity += 1;

> -  if (parts.step != NULL_TREE && !integer_onep (parts.step))

> +  /* Don't increase the complexity of adding a scaled index if it's

> +     the only kind of index that the target allows.  */

> +  if (parts.step != NULL_TREE && ok_without_ratio_p)

>      cost.complexity += 1;

>    if (parts.base != NULL_TREE && parts.index != NULL_TREE)

>      cost.complexity += 1;
diff mbox series

Patch

Index: gcc/tree-ssa-loop-ivopts.c
===================================================================
--- gcc/tree-ssa-loop-ivopts.c	2017-11-03 12:20:07.041206480 +0000
+++ gcc/tree-ssa-loop-ivopts.c	2017-11-03 12:20:07.193201997 +0000
@@ -4333,18 +4333,25 @@  get_address_cost (struct ivopts_data *da
   machine_mode addr_mode = TYPE_MODE (type);
   machine_mode mem_mode = TYPE_MODE (TREE_TYPE (*use->op_p));
   addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (use->iv->base));
+  /* Only true if ratio != 1.  */
+  bool ok_with_ratio_p = false;
+  bool ok_without_ratio_p = false;
 
   if (!aff_combination_const_p (aff_inv))
     {
       parts.index = integer_one_node;
       /* Addressing mode "base + index".  */
-      if (valid_mem_ref_p (mem_mode, as, &parts))
+      ok_without_ratio_p = valid_mem_ref_p (mem_mode, as, &parts);
+      if (ratio != 1)
 	{
 	  parts.step = wide_int_to_tree (type, ratio);
 	  /* Addressing mode "base + index << scale".  */
-	  if (ratio != 1 && !valid_mem_ref_p (mem_mode, as, &parts))
+	  ok_with_ratio_p = valid_mem_ref_p (mem_mode, as, &parts);
+	  if (!ok_with_ratio_p)
 	    parts.step = NULL_TREE;
-
+	}
+      if (ok_with_ratio_p || ok_without_ratio_p)
+	{
 	  if (maybe_nonzero (aff_inv->offset))
 	    {
 	      parts.offset = wide_int_to_tree (sizetype, aff_inv->offset);
@@ -4444,7 +4451,9 @@  get_address_cost (struct ivopts_data *da
 
   if (parts.symbol != NULL_TREE)
     cost.complexity += 1;
-  if (parts.step != NULL_TREE && !integer_onep (parts.step))
+  /* Don't increase the complexity of adding a scaled index if it's
+     the only kind of index that the target allows.  */
+  if (parts.step != NULL_TREE && ok_without_ratio_p)
     cost.complexity += 1;
   if (parts.base != NULL_TREE && parts.index != NULL_TREE)
     cost.complexity += 1;