vect: Move vector costs to loop_vec_info

Message ID mpth7cm29tc.fsf@arm.com
State Committed
Commit 4725f62789f25b17967695203d7ee821221e2dd6
Headers
Series vect: Move vector costs to loop_vec_info |

Commit Message

Richard Sandiford Nov. 8, 2021, 10:58 a.m. UTC
  target_cost_data is in vec_info but is really specific to
loop_vec_info.  This patch moves it there and renames it to
vector_costs, to distinguish it from scalar target costs.

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

Richard


gcc/
	* tree-vectorizer.h (vec_info::target_cost_data): Replace with...
	(_loop_vec_info::vector_costs): ...this.
	(LOOP_VINFO_TARGET_COST_DATA): Delete.
	* tree-vectorizer.c (vec_info::vec_info): Remove target_cost_data
	initialization.
	(vec_info::~vec_info): Remove corresponding delete.
	* tree-vect-loop.c (_loop_vec_info::_loop_vec_info): Initialize
	vector_costs to null.
	(_loop_vec_info::~_loop_vec_info): Delete vector_costs.
	(vect_analyze_loop_operations): Update after above changes.
	(vect_analyze_loop_2): Likewise.
	(vect_estimate_min_profitable_iters): Likewise.
	* tree-vect-slp.c (vect_slp_analyze_operations): Likewise.
---
 gcc/tree-vect-loop.c  | 14 ++++++++------
 gcc/tree-vect-slp.c   | 13 ++++++-------
 gcc/tree-vectorizer.c |  4 +---
 gcc/tree-vectorizer.h |  7 +++----
 4 files changed, 18 insertions(+), 20 deletions(-)
  

Comments

Richard Biener Nov. 8, 2021, 11:06 a.m. UTC | #1
On Mon, Nov 8, 2021 at 11:59 AM Richard Sandiford via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> target_cost_data is in vec_info but is really specific to
> loop_vec_info.  This patch moves it there and renames it to
> vector_costs, to distinguish it from scalar target costs.
>
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

OK.

Thanks,
Richard.

> Richard
>
>
> gcc/
>         * tree-vectorizer.h (vec_info::target_cost_data): Replace with...
>         (_loop_vec_info::vector_costs): ...this.
>         (LOOP_VINFO_TARGET_COST_DATA): Delete.
>         * tree-vectorizer.c (vec_info::vec_info): Remove target_cost_data
>         initialization.
>         (vec_info::~vec_info): Remove corresponding delete.
>         * tree-vect-loop.c (_loop_vec_info::_loop_vec_info): Initialize
>         vector_costs to null.
>         (_loop_vec_info::~_loop_vec_info): Delete vector_costs.
>         (vect_analyze_loop_operations): Update after above changes.
>         (vect_analyze_loop_2): Likewise.
>         (vect_estimate_min_profitable_iters): Likewise.
>         * tree-vect-slp.c (vect_slp_analyze_operations): Likewise.
> ---
>  gcc/tree-vect-loop.c  | 14 ++++++++------
>  gcc/tree-vect-slp.c   | 13 ++++++-------
>  gcc/tree-vectorizer.c |  4 +---
>  gcc/tree-vectorizer.h |  7 +++----
>  4 files changed, 18 insertions(+), 20 deletions(-)
>
> diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
> index a28bb6321d7..b6a631d4384 100644
> --- a/gcc/tree-vect-loop.c
> +++ b/gcc/tree-vect-loop.c
> @@ -821,6 +821,7 @@ _loop_vec_info::_loop_vec_info (class loop *loop_in, vec_info_shared *shared)
>      num_iters (NULL_TREE),
>      num_iters_unchanged (NULL_TREE),
>      num_iters_assumptions (NULL_TREE),
> +    vector_costs (nullptr),
>      th (0),
>      versioning_threshold (0),
>      vectorization_factor (0),
> @@ -932,6 +933,7 @@ _loop_vec_info::~_loop_vec_info ()
>    delete ivexpr_map;
>    delete scan_map;
>    epilogue_vinfos.release ();
> +  delete vector_costs;
>
>    /* When we release an epiloge vinfo that we do not intend to use
>       avoid clearing AUX of the main loop which should continue to
> @@ -1765,7 +1767,7 @@ vect_analyze_loop_operations (loop_vec_info loop_vinfo)
>          }
>      } /* bbs */
>
> -  add_stmt_costs (loop_vinfo->target_cost_data, &cost_vec);
> +  add_stmt_costs (loop_vinfo->vector_costs, &cost_vec);
>
>    /* All operations in the loop are either irrelevant (deal with loop
>       control, or dead), or only used outside the loop and can be moved
> @@ -2375,7 +2377,7 @@ start_over:
>                    LOOP_VINFO_INT_NITERS (loop_vinfo));
>      }
>
> -  LOOP_VINFO_TARGET_COST_DATA (loop_vinfo) = init_cost (loop_vinfo, false);
> +  loop_vinfo->vector_costs = init_cost (loop_vinfo, false);
>
>    /* Analyze the alignment of the data-refs in the loop.
>       Fail if a data reference is found that cannot be vectorized.  */
> @@ -2742,8 +2744,8 @@ again:
>    LOOP_VINFO_COMP_ALIAS_DDRS (loop_vinfo).release ();
>    LOOP_VINFO_CHECK_UNEQUAL_ADDRS (loop_vinfo).release ();
>    /* Reset target cost data.  */
> -  delete LOOP_VINFO_TARGET_COST_DATA (loop_vinfo);
> -  LOOP_VINFO_TARGET_COST_DATA (loop_vinfo) = nullptr;
> +  delete loop_vinfo->vector_costs;
> +  loop_vinfo->vector_costs = nullptr;
>    /* Reset accumulated rgroup information.  */
>    release_vec_loop_controls (&LOOP_VINFO_MASKS (loop_vinfo));
>    release_vec_loop_controls (&LOOP_VINFO_LENS (loop_vinfo));
> @@ -3919,7 +3921,7 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
>    int scalar_outside_cost = 0;
>    int assumed_vf = vect_vf_for_cost (loop_vinfo);
>    int npeel = LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo);
> -  vector_costs *target_cost_data = LOOP_VINFO_TARGET_COST_DATA (loop_vinfo);
> +  vector_costs *target_cost_data = loop_vinfo->vector_costs;
>
>    /* Cost model disabled.  */
>    if (unlimited_cost_model (LOOP_VINFO_LOOP (loop_vinfo)))
> @@ -4265,7 +4267,7 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
>      }
>
>    /* Complete the target-specific cost calculations.  */
> -  finish_cost (LOOP_VINFO_TARGET_COST_DATA (loop_vinfo), &vec_prologue_cost,
> +  finish_cost (loop_vinfo->vector_costs, &vec_prologue_cost,
>                &vec_inside_cost, &vec_epilogue_cost);
>
>    vec_outside_cost = (int)(vec_prologue_cost + vec_epilogue_cost);
> diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
> index 7e1061c8c4e..d437bfd20d0 100644
> --- a/gcc/tree-vect-slp.c
> +++ b/gcc/tree-vect-slp.c
> @@ -4889,16 +4889,15 @@ vect_slp_analyze_operations (vec_info *vinfo)
>        else
>         {
>           i++;
> -
> -         /* For BB vectorization remember the SLP graph entry
> -            cost for later.  */
> -         if (is_a <bb_vec_info> (vinfo))
> -           instance->cost_vec = cost_vec;
> -         else
> +         if (loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo))
>             {
> -             add_stmt_costs (vinfo->target_cost_data, &cost_vec);
> +             add_stmt_costs (loop_vinfo->vector_costs, &cost_vec);
>               cost_vec.release ();
>             }
> +         else
> +           /* For BB vectorization remember the SLP graph entry
> +              cost for later.  */
> +           instance->cost_vec = cost_vec;
>         }
>      }
>
> diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
> index a2e13acb6d2..9ef76ce654b 100644
> --- a/gcc/tree-vectorizer.c
> +++ b/gcc/tree-vectorizer.c
> @@ -459,8 +459,7 @@ shrink_simd_arrays
>  vec_info::vec_info (vec_info::vec_kind kind_in, vec_info_shared *shared_)
>    : kind (kind_in),
>      shared (shared_),
> -    stmt_vec_info_ro (false),
> -    target_cost_data (nullptr)
> +    stmt_vec_info_ro (false)
>  {
>    stmt_vec_infos.create (50);
>  }
> @@ -470,7 +469,6 @@ vec_info::~vec_info ()
>    for (slp_instance &instance : slp_instances)
>      vect_free_slp_instance (instance);
>
> -  delete target_cost_data;
>    free_stmt_vec_infos ();
>  }
>
> diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
> index b552e9dccce..1cd6cc036f2 100644
> --- a/gcc/tree-vectorizer.h
> +++ b/gcc/tree-vectorizer.h
> @@ -408,9 +408,6 @@ public:
>       stmt in the chain.  */
>    auto_vec<stmt_vec_info> grouped_stores;
>
> -  /* Cost data used by the target cost model.  */
> -  class vector_costs *target_cost_data;
> -
>    /* The set of vector modes used in the vectorized region.  */
>    mode_set used_vector_modes;
>
> @@ -590,6 +587,9 @@ public:
>    /* Condition under which this loop is analyzed and versioned.  */
>    tree num_iters_assumptions;
>
> +  /* The cost of the vector code.  */
> +  class vector_costs *vector_costs;
> +
>    /* Threshold of number of iterations below which vectorization will not be
>       performed. It is calculated from MIN_PROFITABLE_ITERS and
>       param_min_vect_loop_bound.  */
> @@ -843,7 +843,6 @@ public:
>  #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
>  #define LOOP_VINFO_REDUCTIONS(L)           (L)->reductions
>  #define LOOP_VINFO_REDUCTION_CHAINS(L)     (L)->reduction_chains
> -#define LOOP_VINFO_TARGET_COST_DATA(L)     (L)->target_cost_data
>  #define LOOP_VINFO_PEELING_FOR_GAPS(L)     (L)->peeling_for_gaps
>  #define LOOP_VINFO_PEELING_FOR_NITER(L)    (L)->peeling_for_niter
>  #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
> --
> 2.25.1
  

Patch

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index a28bb6321d7..b6a631d4384 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -821,6 +821,7 @@  _loop_vec_info::_loop_vec_info (class loop *loop_in, vec_info_shared *shared)
     num_iters (NULL_TREE),
     num_iters_unchanged (NULL_TREE),
     num_iters_assumptions (NULL_TREE),
+    vector_costs (nullptr),
     th (0),
     versioning_threshold (0),
     vectorization_factor (0),
@@ -932,6 +933,7 @@  _loop_vec_info::~_loop_vec_info ()
   delete ivexpr_map;
   delete scan_map;
   epilogue_vinfos.release ();
+  delete vector_costs;
 
   /* When we release an epiloge vinfo that we do not intend to use
      avoid clearing AUX of the main loop which should continue to
@@ -1765,7 +1767,7 @@  vect_analyze_loop_operations (loop_vec_info loop_vinfo)
         }
     } /* bbs */
 
-  add_stmt_costs (loop_vinfo->target_cost_data, &cost_vec);
+  add_stmt_costs (loop_vinfo->vector_costs, &cost_vec);
 
   /* All operations in the loop are either irrelevant (deal with loop
      control, or dead), or only used outside the loop and can be moved
@@ -2375,7 +2377,7 @@  start_over:
 		   LOOP_VINFO_INT_NITERS (loop_vinfo));
     }
 
-  LOOP_VINFO_TARGET_COST_DATA (loop_vinfo) = init_cost (loop_vinfo, false);
+  loop_vinfo->vector_costs = init_cost (loop_vinfo, false);
 
   /* Analyze the alignment of the data-refs in the loop.
      Fail if a data reference is found that cannot be vectorized.  */
@@ -2742,8 +2744,8 @@  again:
   LOOP_VINFO_COMP_ALIAS_DDRS (loop_vinfo).release ();
   LOOP_VINFO_CHECK_UNEQUAL_ADDRS (loop_vinfo).release ();
   /* Reset target cost data.  */
-  delete LOOP_VINFO_TARGET_COST_DATA (loop_vinfo);
-  LOOP_VINFO_TARGET_COST_DATA (loop_vinfo) = nullptr;
+  delete loop_vinfo->vector_costs;
+  loop_vinfo->vector_costs = nullptr;
   /* Reset accumulated rgroup information.  */
   release_vec_loop_controls (&LOOP_VINFO_MASKS (loop_vinfo));
   release_vec_loop_controls (&LOOP_VINFO_LENS (loop_vinfo));
@@ -3919,7 +3921,7 @@  vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
   int scalar_outside_cost = 0;
   int assumed_vf = vect_vf_for_cost (loop_vinfo);
   int npeel = LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo);
-  vector_costs *target_cost_data = LOOP_VINFO_TARGET_COST_DATA (loop_vinfo);
+  vector_costs *target_cost_data = loop_vinfo->vector_costs;
 
   /* Cost model disabled.  */
   if (unlimited_cost_model (LOOP_VINFO_LOOP (loop_vinfo)))
@@ -4265,7 +4267,7 @@  vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
     }
 
   /* Complete the target-specific cost calculations.  */
-  finish_cost (LOOP_VINFO_TARGET_COST_DATA (loop_vinfo), &vec_prologue_cost,
+  finish_cost (loop_vinfo->vector_costs, &vec_prologue_cost,
 	       &vec_inside_cost, &vec_epilogue_cost);
 
   vec_outside_cost = (int)(vec_prologue_cost + vec_epilogue_cost);
diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c
index 7e1061c8c4e..d437bfd20d0 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -4889,16 +4889,15 @@  vect_slp_analyze_operations (vec_info *vinfo)
       else
 	{
 	  i++;
-
-	  /* For BB vectorization remember the SLP graph entry
-	     cost for later.  */
-	  if (is_a <bb_vec_info> (vinfo))
-	    instance->cost_vec = cost_vec;
-	  else
+	  if (loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo))
 	    {
-	      add_stmt_costs (vinfo->target_cost_data, &cost_vec);
+	      add_stmt_costs (loop_vinfo->vector_costs, &cost_vec);
 	      cost_vec.release ();
 	    }
+	  else
+	    /* For BB vectorization remember the SLP graph entry
+	       cost for later.  */
+	    instance->cost_vec = cost_vec;
 	}
     }
 
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index a2e13acb6d2..9ef76ce654b 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -459,8 +459,7 @@  shrink_simd_arrays
 vec_info::vec_info (vec_info::vec_kind kind_in, vec_info_shared *shared_)
   : kind (kind_in),
     shared (shared_),
-    stmt_vec_info_ro (false),
-    target_cost_data (nullptr)
+    stmt_vec_info_ro (false)
 {
   stmt_vec_infos.create (50);
 }
@@ -470,7 +469,6 @@  vec_info::~vec_info ()
   for (slp_instance &instance : slp_instances)
     vect_free_slp_instance (instance);
 
-  delete target_cost_data;
   free_stmt_vec_infos ();
 }
 
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index b552e9dccce..1cd6cc036f2 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -408,9 +408,6 @@  public:
      stmt in the chain.  */
   auto_vec<stmt_vec_info> grouped_stores;
 
-  /* Cost data used by the target cost model.  */
-  class vector_costs *target_cost_data;
-
   /* The set of vector modes used in the vectorized region.  */
   mode_set used_vector_modes;
 
@@ -590,6 +587,9 @@  public:
   /* Condition under which this loop is analyzed and versioned.  */
   tree num_iters_assumptions;
 
+  /* The cost of the vector code.  */
+  class vector_costs *vector_costs;
+
   /* Threshold of number of iterations below which vectorization will not be
      performed. It is calculated from MIN_PROFITABLE_ITERS and
      param_min_vect_loop_bound.  */
@@ -843,7 +843,6 @@  public:
 #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
 #define LOOP_VINFO_REDUCTIONS(L)           (L)->reductions
 #define LOOP_VINFO_REDUCTION_CHAINS(L)     (L)->reduction_chains
-#define LOOP_VINFO_TARGET_COST_DATA(L)     (L)->target_cost_data
 #define LOOP_VINFO_PEELING_FOR_GAPS(L)     (L)->peeling_for_gaps
 #define LOOP_VINFO_PEELING_FOR_NITER(L)    (L)->peeling_for_niter
 #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies