vect: Pass scalar_costs to finish_cost

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.
This commit is contained in:
Richard Sandiford 2021-11-10 12:31:02 +00:00
parent 6ddc6a57a7
commit 0612883d9d
6 changed files with 23 additions and 18 deletions

View 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 *);

View 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. */

View 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);

View 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;

View 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;

View 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 ();