From 211cd1e2358d52d3863f727b650c65650dd5ce89 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 1 Aug 2018 14:59:51 +0000 Subject: [PATCH] [04/11] Add a vect_orig_stmt helper function This patch just adds a helper function for going from a potential pattern statement to the original scalar statement. 2018-08-01 Richard Sandiford gcc/ * tree-vectorizer.h (vect_orig_stmt): New function. * tree-vect-data-refs.c (vect_preserves_scalar_order_p): Use it. * tree-vect-loop.c (vect_model_reduction_cost): Likewise. (vect_create_epilog_for_reduction): Likewise. (vectorizable_live_operation): Likewise. * tree-vect-slp.c (vect_find_last_scalar_stmt_in_slp): Likewise. (vect_detect_hybrid_slp_stmts, vect_schedule_slp): Likewise. * tree-vect-stmts.c (vectorizable_call): Likewise. (vectorizable_simd_clone_call, vect_remove_stores): Likewise. From-SVN: r263217 --- gcc/ChangeLog | 12 ++++++++++++ gcc/tree-vect-data-refs.c | 6 ++---- gcc/tree-vect-loop.c | 26 ++++++-------------------- gcc/tree-vect-slp.c | 11 +++-------- gcc/tree-vect-stmts.c | 11 +++-------- gcc/tree-vectorizer.h | 11 +++++++++++ 6 files changed, 37 insertions(+), 40 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index be6b24c0478..decc5cffd4a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2018-08-01 Richard Sandiford + + * tree-vectorizer.h (vect_orig_stmt): New function. + * tree-vect-data-refs.c (vect_preserves_scalar_order_p): Use it. + * tree-vect-loop.c (vect_model_reduction_cost): Likewise. + (vect_create_epilog_for_reduction): Likewise. + (vectorizable_live_operation): Likewise. + * tree-vect-slp.c (vect_find_last_scalar_stmt_in_slp): Likewise. + (vect_detect_hybrid_slp_stmts, vect_schedule_slp): Likewise. + * tree-vect-stmts.c (vectorizable_call): Likewise. + (vectorizable_simd_clone_call, vect_remove_stores): Likewise. + 2018-08-01 Richard Sandiford * tree-vectorizer.h (vect_transform_stmt): Remove grouped_store diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c index 2158bf4e2f6..1f09bd520cc 100644 --- a/gcc/tree-vect-data-refs.c +++ b/gcc/tree-vect-data-refs.c @@ -214,10 +214,8 @@ vect_preserves_scalar_order_p (dr_vec_info *dr_info_a, dr_vec_info *dr_info_b) (but could happen later) while reads will happen no later than their current position (but could happen earlier). Reordering is therefore only possible if the first access is a write. */ - if (is_pattern_stmt_p (stmtinfo_a)) - stmtinfo_a = STMT_VINFO_RELATED_STMT (stmtinfo_a); - if (is_pattern_stmt_p (stmtinfo_b)) - stmtinfo_b = STMT_VINFO_RELATED_STMT (stmtinfo_b); + stmtinfo_a = vect_orig_stmt (stmtinfo_a); + stmtinfo_b = vect_orig_stmt (stmtinfo_b); stmt_vec_info earlier_stmt_info = get_earlier_stmt (stmtinfo_a, stmtinfo_b); return !DR_IS_WRITE (STMT_VINFO_DATA_REF (earlier_stmt_info)); } diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 29f980a3f37..b5d1671aa6b 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -3814,10 +3814,7 @@ vect_model_reduction_cost (stmt_vec_info stmt_info, internal_fn reduc_fn, vectype = STMT_VINFO_VECTYPE (stmt_info); mode = TYPE_MODE (vectype); - stmt_vec_info orig_stmt_info = STMT_VINFO_RELATED_STMT (stmt_info); - - if (!orig_stmt_info) - orig_stmt_info = stmt_info; + stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info); code = gimple_assign_rhs_code (orig_stmt_info->stmt); @@ -4738,13 +4735,8 @@ vect_create_epilog_for_reduction (vec vect_defs, Otherwise (it is a regular reduction) - the tree-code and scalar-def are taken from STMT. */ - stmt_vec_info orig_stmt_info = STMT_VINFO_RELATED_STMT (stmt_info); - if (!orig_stmt_info) - { - /* Regular reduction */ - orig_stmt_info = stmt_info; - } - else + stmt_vec_info orig_stmt_info = vect_orig_stmt (stmt_info); + if (orig_stmt_info != stmt_info) { /* Reduction pattern */ gcc_assert (STMT_VINFO_IN_PATTERN_P (orig_stmt_info)); @@ -5540,11 +5532,7 @@ vect_finalize_reduction: if (REDUC_GROUP_FIRST_ELEMENT (stmt_info)) { stmt_vec_info dest_stmt_info - = SLP_TREE_SCALAR_STMTS (slp_node)[group_size - 1]; - /* Handle reduction patterns. */ - if (STMT_VINFO_RELATED_STMT (dest_stmt_info)) - dest_stmt_info = STMT_VINFO_RELATED_STMT (dest_stmt_info); - + = vect_orig_stmt (SLP_TREE_SCALAR_STMTS (slp_node)[group_size - 1]); scalar_dest = gimple_assign_lhs (dest_stmt_info->stmt); group_size = 1; } @@ -7898,10 +7886,8 @@ vectorizable_live_operation (stmt_vec_info stmt_info, return true; } - /* If stmt has a related stmt, then use that for getting the lhs. */ - gimple *stmt = (is_pattern_stmt_p (stmt_info) - ? STMT_VINFO_RELATED_STMT (stmt_info)->stmt - : stmt_info->stmt); + /* Use the lhs of the original scalar statement. */ + gimple *stmt = vect_orig_stmt (stmt_info)->stmt; lhs = (is_a (stmt)) ? gimple_phi_result (stmt) : gimple_get_lhs (stmt); diff --git a/gcc/tree-vect-slp.c b/gcc/tree-vect-slp.c index cee2c7f21a5..f9a83dd77ba 100644 --- a/gcc/tree-vect-slp.c +++ b/gcc/tree-vect-slp.c @@ -1848,8 +1848,7 @@ vect_find_last_scalar_stmt_in_slp (slp_tree node) for (int i = 0; SLP_TREE_SCALAR_STMTS (node).iterate (i, &stmt_vinfo); i++) { - if (is_pattern_stmt_p (stmt_vinfo)) - stmt_vinfo = STMT_VINFO_RELATED_STMT (stmt_vinfo); + stmt_vinfo = vect_orig_stmt (stmt_vinfo); last = last ? get_later_stmt (stmt_vinfo, last) : stmt_vinfo; } @@ -2314,10 +2313,7 @@ vect_detect_hybrid_slp_stmts (slp_tree node, unsigned i, slp_vect_type stype) gcc_checking_assert (PURE_SLP_STMT (stmt_vinfo)); /* If we get a pattern stmt here we have to use the LHS of the original stmt for immediate uses. */ - gimple *stmt = stmt_vinfo->stmt; - if (! STMT_VINFO_IN_PATTERN_P (stmt_vinfo) - && STMT_VINFO_RELATED_STMT (stmt_vinfo)) - stmt = STMT_VINFO_RELATED_STMT (stmt_vinfo)->stmt; + gimple *stmt = vect_orig_stmt (stmt_vinfo)->stmt; tree def; if (gimple_code (stmt) == GIMPLE_PHI) def = gimple_phi_result (stmt); @@ -4087,8 +4083,7 @@ vect_schedule_slp (vec_info *vinfo) if (!STMT_VINFO_DATA_REF (store_info)) break; - if (is_pattern_stmt_p (store_info)) - store_info = STMT_VINFO_RELATED_STMT (store_info); + store_info = vect_orig_stmt (store_info); /* Free the attached stmt_vec_info and remove the stmt. */ vinfo->remove_stmt (store_info); } diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 28d5f8d165c..f3a2d80f98c 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -3628,8 +3628,7 @@ vectorizable_call (stmt_vec_info stmt_info, gimple_stmt_iterator *gsi, if (slp_node) return true; - if (is_pattern_stmt_p (stmt_info)) - stmt_info = STMT_VINFO_RELATED_STMT (stmt_info); + stmt_info = vect_orig_stmt (stmt_info); lhs = gimple_get_lhs (stmt_info->stmt); gassign *new_stmt @@ -4364,10 +4363,7 @@ vectorizable_simd_clone_call (stmt_vec_info stmt_info, if (scalar_dest) { type = TREE_TYPE (scalar_dest); - if (is_pattern_stmt_p (stmt_info)) - lhs = gimple_call_lhs (STMT_VINFO_RELATED_STMT (stmt_info)->stmt); - else - lhs = gimple_call_lhs (stmt); + lhs = gimple_call_lhs (vect_orig_stmt (stmt_info)->stmt); new_stmt = gimple_build_assign (lhs, build_zero_cst (type)); } else @@ -9843,8 +9839,7 @@ vect_remove_stores (stmt_vec_info first_stmt_info) while (next_stmt_info) { stmt_vec_info tmp = DR_GROUP_NEXT_ELEMENT (next_stmt_info); - if (is_pattern_stmt_p (next_stmt_info)) - next_stmt_info = STMT_VINFO_RELATED_STMT (next_stmt_info); + next_stmt_info = vect_orig_stmt (next_stmt_info); /* Free the attached stmt_vec_info and remove the stmt. */ vinfo->remove_stmt (next_stmt_info); next_stmt_info = tmp; diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h index 37833ce81ef..a8403d5299c 100644 --- a/gcc/tree-vectorizer.h +++ b/gcc/tree-vectorizer.h @@ -1120,6 +1120,17 @@ is_pattern_stmt_p (stmt_vec_info stmt_info) return stmt_info->pattern_stmt_p; } +/* If STMT_INFO is a pattern statement, return the statement that it + replaces, otherwise return STMT_INFO itself. */ + +inline stmt_vec_info +vect_orig_stmt (stmt_vec_info stmt_info) +{ + if (is_pattern_stmt_p (stmt_info)) + return STMT_VINFO_RELATED_STMT (stmt_info); + return stmt_info; +} + /* Return true if BB is a loop header. */ static inline bool -- 2.30.2