fix scalar BB vectorization costing

We were costing the scalar pattern stmts rather than the scalar
original stmt and also not appropriately looking at the pattern
stmt for whether the stmt is vectorized.

2020-07-03  Richard Biener  <rguenther@suse.de>

	* tree-vect-slp.c (vect_bb_slp_scalar_cost): Cost the
	original non-pattern stmts, look at the pattern stmt
	vectorization status.

	* gcc.dg/vect/costmodel/x86_64/costmodel-vect-slp-2.c: New
	testcase.
This commit is contained in:
Richard Biener 2020-07-03 11:28:53 +02:00
parent bf628a97ef
commit 9bc2c2347d
2 changed files with 28 additions and 12 deletions

View file

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-additional-options "-fdump-tree-slp-details" } */
int a[4], b[4];
void foo()
{
a[0] = b[0] / 7;
a[1] = b[1] / 7;
a[2] = b[2] / 7;
a[3] = b[3] / 7;
}
/* We should cost the original division stmt, not the scalar pattern stmts. */
/* { dg-final { scan-tree-dump-times " / 7 1 times scalar_stmt costs" 4 "slp2" } } */

View file

@ -3039,7 +3039,6 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
FOR_EACH_VEC_ELT (SLP_TREE_SCALAR_STMTS (node), i, stmt_info)
{
gimple *stmt = stmt_info->stmt;
ssa_op_iter op_iter;
def_operand_p def_p;
@ -3051,7 +3050,9 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
required defs in the SLP children in the scalar cost. This
way we make the vectorization more costly when compared to
the scalar cost. */
FOR_EACH_SSA_DEF_OPERAND (def_p, stmt, op_iter, SSA_OP_DEF)
stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info);
gimple *orig_stmt = orig_stmt_info->stmt;
FOR_EACH_SSA_DEF_OPERAND (def_p, orig_stmt, op_iter, SSA_OP_DEF)
{
imm_use_iterator use_iter;
gimple *use_stmt;
@ -3059,7 +3060,8 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
if (!is_gimple_debug (use_stmt))
{
stmt_vec_info use_stmt_info = vinfo->lookup_stmt (use_stmt);
if (!use_stmt_info || !PURE_SLP_STMT (use_stmt_info))
if (!use_stmt_info
|| !PURE_SLP_STMT (vect_stmt_to_vectorize (use_stmt_info)))
{
(*life)[i] = true;
BREAK_FROM_IMM_USE_STMT (use_iter);
@ -3070,23 +3072,23 @@ vect_bb_slp_scalar_cost (vec_info *vinfo,
continue;
/* Count scalar stmts only once. */
if (gimple_visited_p (stmt))
if (gimple_visited_p (orig_stmt))
continue;
gimple_set_visited (stmt, true);
gimple_set_visited (orig_stmt, true);
vect_cost_for_stmt kind;
if (STMT_VINFO_DATA_REF (stmt_info))
{
if (DR_IS_READ (STMT_VINFO_DATA_REF (stmt_info)))
if (STMT_VINFO_DATA_REF (orig_stmt_info))
{
if (DR_IS_READ (STMT_VINFO_DATA_REF (orig_stmt_info)))
kind = scalar_load;
else
else
kind = scalar_store;
}
else if (vect_nop_conversion_p (stmt_info))
}
else if (vect_nop_conversion_p (orig_stmt_info))
continue;
else
kind = scalar_stmt;
record_stmt_cost (cost_vec, 1, kind, stmt_info, 0, vect_body);
record_stmt_cost (cost_vec, 1, kind, orig_stmt_info, 0, vect_body);
}
auto_vec<bool, 20> subtree_life;