]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
vect: Pass scalar_costs to finish_cost
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 10 Nov 2021 12:31:02 +0000 (12:31 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 10 Nov 2021 12:31:02 +0000 (12:31 +0000)
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.

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
gcc/config/rs6000/rs6000.c
gcc/tree-vect-loop.c
gcc/tree-vect-slp.c
gcc/tree-vectorizer.c
gcc/tree-vectorizer.h

index e23d7cf3d8fa361f2b732c95e773a059769e8215..cd4332d04e548aede63cb4ab269bc4ffeb87f2e6 100644 (file)
@@ -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 *);
index 1f2aa60348b642073543ac4fdc9ae29306d0cc31..e4843eb0f1cf57de3d6d64f363f1ead1c463a203 100644 (file)
@@ -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.  */
index 21530126cf63532f79f5466776b5130ed86ec623..1cd5dbcb6f7788b467a74b09385c4938525524b3 100644 (file)
@@ -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);
 
index d437bfd20d0ae377850b7da90d03276871462aca..94c75497495b6f28358120bc14af001fcaf027f4 100644 (file)
@@ -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;
index dcbb2a3f13af78cdef028b80b4afcffb41b6ae8c..71f12b3257e69a033eb23fe4fe05f8c342a290d8 100644 (file)
@@ -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;
index a8ce3083c445aca837779490b794a43cd850c49a..f8f306415121a970d2ec836b1fbf7ec0c75ad2df 100644 (file)
@@ -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 ();