From: Richard Sandiford Date: Wed, 13 Nov 2019 09:03:07 +0000 (+0000) Subject: Don't assign a cost to vectorizable_assignment X-Git-Tag: misc/cutover-git~1315 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4020b28d02a00d478a3a769855ae6a8d9cc6b26;p=thirdparty%2Fgcc.git Don't assign a cost to vectorizable_assignment vectorizable_assignment handles true SSA-to-SSA copies (which hopefully we don't see in practice) and no-op conversions that are required to maintain correct gimple, such as changes between signed and unsigned types. These cases shouldn't generate any code and so shouldn't count against either the scalar or vector costs. Later patches test this, but it seemed worth splitting out. 2019-11-13 Richard Sandiford gcc/ * tree-vectorizer.h (vect_nop_conversion_p): Declare. * tree-vect-stmts.c (vect_nop_conversion_p): New function. (vectorizable_assignment): Don't add a cost for nop conversions. * tree-vect-loop.c (vect_compute_single_scalar_iteration_cost): Likewise. * tree-vect-slp.c (vect_bb_slp_scalar_cost): Likewise. From-SVN: r278122 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cb3439569478..9054178018ea 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2019-11-13 Richard Sandiford + + * tree-vectorizer.h (vect_nop_conversion_p): Declare. + * tree-vect-stmts.c (vect_nop_conversion_p): New function. + (vectorizable_assignment): Don't add a cost for nop conversions. + * tree-vect-loop.c (vect_compute_single_scalar_iteration_cost): + Likewise. + * tree-vect-slp.c (vect_bb_slp_scalar_cost): Likewise. + 2019-11-13 Richard Sandiford * tree-vect-stmts.c (vect_model_promotion_demotion_cost): Take the diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index d9f413430dc1..75ec9e67a5c7 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -1125,7 +1125,9 @@ vect_compute_single_scalar_iteration_cost (loop_vec_info loop_vinfo) else kind = scalar_store; } - else + else if (vect_nop_conversion_p (stmt_info)) + continue; + else kind = scalar_stmt; record_stmt_cost (&LOOP_VINFO_SCALAR_ITERATION_COST (loop_vinfo), diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index 4bc0cc77de4f..a2c70ec5cd6e 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -2893,6 +2893,8 @@ vect_bb_slp_scalar_cost (basic_block bb, else kind = scalar_store; } + else if (vect_nop_conversion_p (stmt_info)) + continue; else kind = scalar_stmt; record_stmt_cost (cost_vec, 1, kind, stmt_info, 0, vect_body); diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 53f4189d939f..c8a43ada16f7 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -5281,6 +5281,29 @@ vectorizable_conversion (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, return true; } +/* Return true if we can assume from the scalar form of STMT_INFO that + neither the scalar nor the vector forms will generate code. STMT_INFO + is known not to involve a data reference. */ + +bool +vect_nop_conversion_p (stmt_vec_info stmt_info) +{ + gassign *stmt = dyn_cast (stmt_info->stmt); + if (!stmt) + return false; + + tree lhs = gimple_assign_lhs (stmt); + tree_code code = gimple_assign_rhs_code (stmt); + tree rhs = gimple_assign_rhs1 (stmt); + + if (code == SSA_NAME || code == VIEW_CONVERT_EXPR) + return true; + + if (CONVERT_EXPR_CODE_P (code)) + return tree_nop_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)); + + return false; +} /* Function vectorizable_assignment. @@ -5396,7 +5419,9 @@ vectorizable_assignment (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, { STMT_VINFO_TYPE (stmt_info) = assignment_vec_info_type; DUMP_VECT_SCOPE ("vectorizable_assignment"); - vect_model_simple_cost (stmt_info, ncopies, dt, ndts, slp_node, cost_vec); + if (!vect_nop_conversion_p (stmt_info)) + vect_model_simple_cost (stmt_info, ncopies, dt, ndts, slp_node, + cost_vec); return true; } diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index e556e0e98886..e93ccc74c665 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -1650,6 +1650,7 @@ extern tree vect_get_vec_def_for_stmt_copy (vec_info *, tree); extern bool vect_transform_stmt (stmt_vec_info, gimple_stmt_iterator *, slp_tree, slp_instance); extern void vect_remove_stores (stmt_vec_info); +extern bool vect_nop_conversion_p (stmt_vec_info); extern opt_result vect_analyze_stmt (stmt_vec_info, bool *, slp_tree, slp_instance, stmt_vector_for_cost *); extern void vect_get_load_cost (stmt_vec_info, int, bool,