[PATCH] vect: Pass scalar_costs to finish_cost

Richard Sandiford richard.sandiford@arm.com
Mon Nov 8 10:47:58 GMT 2021


When finishing the vector costs, it can be useful to know
what the associated scalar costs were.  This allows targets
to read information collected about the original scalar loop
when trying to make a final judgement about the cost of the
vector code.

This patch therefore passes the scalar costs to
vector_costs::finish_cost.  The parameter is null for the
scalar costs themselves.

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

Richard


gcc/
	* tree-vectorizer.h (vector_costs::finish_cost): Take the
	corresponding scalar costs as a parameter.
	(finish_cost): Likewise.
	* tree-vect-loop.c (vect_compute_single_scalar_iteration_cost)
	(vect_estimate_min_profitable_iters): Update accordingly.
	* tree-vect-slp.c (vect_bb_vectorization_profitable_p): Likewise.
	* tree-vectorizer.c (vector_costs::finish_cost): Likewise.
	* config/aarch64/aarch64.c (aarch64_vector_costs::finish_cost):
	Likewise.
	* config/rs6000/rs6000.c (rs6000_cost_data::finish_cost): Likewise.
---
 gcc/config/aarch64/aarch64.c |  6 +++---
 gcc/config/rs6000/rs6000.c   |  6 +++---
 gcc/tree-vect-loop.c         |  6 +++---
 gcc/tree-vect-slp.c          |  7 ++++---
 gcc/tree-vectorizer.c        |  2 +-
 gcc/tree-vectorizer.h        | 14 +++++++++-----
 6 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 19f67415234..ebb937211ed 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -14745,7 +14745,7 @@ public:
 			      stmt_vec_info stmt_info, tree vectype,
 			      int misalign,
 			      vect_cost_model_location where) override;
-  void finish_cost () override;
+  void finish_cost (const vector_costs *) override;
 
 private:
   void record_potential_advsimd_unrolling (loop_vec_info);
@@ -16138,7 +16138,7 @@ aarch64_vector_costs::adjust_body_cost (unsigned int body_cost)
 }
 
 void
-aarch64_vector_costs::finish_cost ()
+aarch64_vector_costs::finish_cost (const vector_costs *scalar_costs)
 {
   loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (m_vinfo);
   if (loop_vinfo
@@ -16146,7 +16146,7 @@ aarch64_vector_costs::finish_cost ()
       && aarch64_use_new_vector_costs_p ())
     m_costs[vect_body] = adjust_body_cost (m_costs[vect_body]);
 
-  vector_costs::finish_cost ();
+  vector_costs::finish_cost (scalar_costs);
 }
 
 static void initialize_aarch64_code_model (struct gcc_options *);
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index ec054800491..cd44ac61336 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -5268,7 +5268,7 @@ public:
 			      stmt_vec_info stmt_info, tree vectype,
 			      int misalign,
 			      vect_cost_model_location where) override;
-  void finish_cost () override;
+  void finish_cost (const vector_costs *) override;
 
 protected:
   void update_target_cost_per_stmt (vect_cost_for_stmt, stmt_vec_info,
@@ -5522,7 +5522,7 @@ rs6000_cost_data::adjust_vect_cost_per_loop (loop_vec_info loop_vinfo)
 }
 
 void
-rs6000_cost_data::finish_cost ()
+rs6000_cost_data::finish_cost (const vector_costs *scalar_costs)
 {
   if (loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (m_vinfo))
     {
@@ -5539,7 +5539,7 @@ rs6000_cost_data::finish_cost ()
 	m_costs[vect_body] += 10000;
     }
 
-  vector_costs::finish_cost ();
+  vector_costs::finish_cost (scalar_costs);
 }
 
 /* Implement targetm.loop_unroll_adjust.  */
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index 887275a5071..190b52142e4 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -1301,7 +1301,7 @@ vect_compute_single_scalar_iteration_cost (loop_vec_info loop_vinfo)
     (void) add_stmt_cost (loop_vinfo->scalar_costs, si->count,
 			  si->kind, si->stmt_info, si->vectype,
 			  si->misalign, si->where);
-  loop_vinfo->scalar_costs->finish_cost ();
+  loop_vinfo->scalar_costs->finish_cost (nullptr);
 }
 
 
@@ -4130,8 +4130,8 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo,
     }
 
   /* Complete the target-specific cost calculations.  */
-  finish_cost (loop_vinfo->vector_costs, &vec_prologue_cost,
-	       &vec_inside_cost, &vec_epilogue_cost);
+  finish_cost (loop_vinfo->vector_costs, loop_vinfo->scalar_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 d437bfd20d0..94c75497495 100644
--- a/gcc/tree-vect-slp.c
+++ b/gcc/tree-vect-slp.c
@@ -5344,7 +5344,8 @@ vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo,
       while (si < li_scalar_costs.length ()
 	     && li_scalar_costs[si].first == sl);
       unsigned dummy;
-      finish_cost (scalar_target_cost_data, &dummy, &scalar_cost, &dummy);
+      finish_cost (scalar_target_cost_data, nullptr,
+		   &dummy, &scalar_cost, &dummy);
       delete scalar_target_cost_data;
 
       /* Complete the target-specific vector cost calculation.  */
@@ -5356,8 +5357,8 @@ vect_bb_vectorization_profitable_p (bb_vec_info bb_vinfo,
 	}
       while (vi < li_vector_costs.length ()
 	     && li_vector_costs[vi].first == vl);
-      finish_cost (vect_target_cost_data, &vec_prologue_cost,
-		   &vec_inside_cost, &vec_epilogue_cost);
+      finish_cost (vect_target_cost_data, scalar_target_cost_data,
+		   &vec_prologue_cost, &vec_inside_cost, &vec_epilogue_cost);
       delete vect_target_cost_data;
 
       vec_outside_cost = vec_prologue_cost + vec_epilogue_cost;
diff --git a/gcc/tree-vectorizer.c b/gcc/tree-vectorizer.c
index dcbb2a3f13a..71f12b3257e 100644
--- a/gcc/tree-vectorizer.c
+++ b/gcc/tree-vectorizer.c
@@ -1703,7 +1703,7 @@ vector_costs::add_stmt_cost (int count, vect_cost_for_stmt kind,
 /* See the comment above the declaration for details.  */
 
 void
-vector_costs::finish_cost ()
+vector_costs::finish_cost (const vector_costs *)
 {
   gcc_assert (!m_finished);
   m_finished = true;
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 8dba3a34aa9..da212334c06 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -1415,8 +1415,11 @@ public:
 				      vect_cost_model_location where);
 
   /* Finish calculating the cost of the code.  The results can be
-     read back using the functions below.  */
-  virtual void finish_cost ();
+     read back using the functions below.
+
+     If the costs describe vector code, SCALAR_COSTS gives the costs
+     of the corresponding scalar code, otherwise it is null.  */
+  virtual void finish_cost (const vector_costs *scalar_costs);
 
   /* The costs in THIS and OTHER both describe ways of vectorizing
      a main loop.  Return true if the costs described by THIS are
@@ -1691,10 +1694,11 @@ add_stmt_cost (vector_costs *costs, stmt_info_for_cost *i)
 /* Alias targetm.vectorize.finish_cost.  */
 
 static inline void
-finish_cost (vector_costs *costs, unsigned *prologue_cost,
-	     unsigned *body_cost, unsigned *epilogue_cost)
+finish_cost (vector_costs *costs, const vector_costs *scalar_costs,
+	     unsigned *prologue_cost, unsigned *body_cost,
+	     unsigned *epilogue_cost)
 {
-  costs->finish_cost ();
+  costs->finish_cost (scalar_costs);
   *prologue_cost = costs->prologue_cost ();
   *body_cost = costs->body_cost ();
   *epilogue_cost = costs->epilogue_cost ();
-- 
2.25.1



More information about the Gcc-patches mailing list