Re: [12/46] Make vect_finish_stmt_generation return a stmt_vec_info
On Tue, Jul 24, 2018 at 11:58 AM Richard Sandiford wrote: > > This patch makes vect_finish_replace_stmt and vect_finish_stmt_generation > return the stmt_vec_info for the vectorised statement, so that the caller > doesn't need a separate vinfo_for_stmt to get at it. > > This involved changing the structure of the statement-generating loops > so that they use narrow scopes for the vectorised gimple statements > and use the existing (wider) scopes for the associated stmt_vec_infos. > This helps with gimple stmt->stmt_vec_info changes further down the line. OK. > The way we do this generation is another area ripe for clean-up, > but that's too much of a rabbit-hole for this series. Indeed ... > > 2018-07-24 Richard Sandiford > > gcc/ > * tree-vectorizer.h (vect_finish_replace_stmt): Return a stmt_vec_info > (vect_finish_stmt_generation): Likewise. > * tree-vect-stmts.c (vect_finish_stmt_generation_1): Likewise. > (vect_finish_replace_stmt, vect_finish_stmt_generation): Likewise. > (vect_build_gather_load_calls): Use the return value of the above > functions instead of a separate call to vinfo_for_stmt. Use narrow > scopes for the input gimple stmt and wider scopes for the associated > stmt_vec_info. Use vec_info::lookup_def when setting these > stmt_vec_infos from an SSA_NAME definition. > (vectorizable_bswap, vectorizable_call, vectorizable_simd_clone_call) > (vect_create_vectorized_demotion_stmts, vectorizable_conversion) > (vectorizable_assignment, vectorizable_shift, vectorizable_operation) > (vectorizable_store, vectorizable_load, vectorizable_condition) > (vectorizable_comparison): Likewise. > * tree-vect-loop.c (vectorize_fold_left_reduction): Likewise. > (vectorizable_reduction): Likewise. > > Index: gcc/tree-vectorizer.h > === > --- gcc/tree-vectorizer.h 2018-07-24 10:22:37.257248166 +0100 > +++ gcc/tree-vectorizer.h 2018-07-24 10:22:40.725217371 +0100 > @@ -1548,9 +1548,9 @@ extern void free_stmt_vec_info (gimple * > extern unsigned record_stmt_cost (stmt_vector_for_cost *, int, > enum vect_cost_for_stmt, stmt_vec_info, > int, enum vect_cost_model_location); > -extern void vect_finish_replace_stmt (gimple *, gimple *); > -extern void vect_finish_stmt_generation (gimple *, gimple *, > - gimple_stmt_iterator *); > +extern stmt_vec_info vect_finish_replace_stmt (gimple *, gimple *); > +extern stmt_vec_info vect_finish_stmt_generation (gimple *, gimple *, > + gimple_stmt_iterator *); > extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info); > extern tree vect_get_store_rhs (gimple *); > extern tree vect_get_vec_def_for_operand_1 (gimple *, enum vect_def_type); > Index: gcc/tree-vect-stmts.c > === > --- gcc/tree-vect-stmts.c 2018-07-24 10:22:37.257248166 +0100 > +++ gcc/tree-vect-stmts.c 2018-07-24 10:22:40.725217371 +0100 > @@ -1729,15 +1729,15 @@ vect_get_vec_defs (tree op0, tree op1, g > > /* Helper function called by vect_finish_replace_stmt and > vect_finish_stmt_generation. Set the location of the new > - statement and create a stmt_vec_info for it. */ > + statement and create and return a stmt_vec_info for it. */ > > -static void > +static stmt_vec_info > vect_finish_stmt_generation_1 (gimple *stmt, gimple *vec_stmt) > { >stmt_vec_info stmt_info = vinfo_for_stmt (stmt); >vec_info *vinfo = stmt_info->vinfo; > > - vinfo->add_stmt (vec_stmt); > + stmt_vec_info vec_stmt_info = vinfo->add_stmt (vec_stmt); > >if (dump_enabled_p ()) > { > @@ -1753,12 +1753,15 @@ vect_finish_stmt_generation_1 (gimple *s >int lp_nr = lookup_stmt_eh_lp (stmt); >if (lp_nr != 0 && stmt_could_throw_p (vec_stmt)) > add_stmt_to_eh_lp (vec_stmt, lp_nr); > + > + return vec_stmt_info; > } > > /* Replace the scalar statement STMT with a new vector statement VEC_STMT, > - which sets the same scalar result as STMT did. */ > + which sets the same scalar result as STMT did. Create and return a > + stmt_vec_info for VEC_STMT. */ > > -void > +stmt_vec_info > vect_finish_replace_stmt (gimple *stmt, gimple *vec_stmt) > { >gcc_assert (gimple_get_lhs (stmt) == gimple_get_lhs (vec_stmt)); > @@ -1766,14 +1769,13 @@ vect_finish_replace_stmt (gimple *stmt, >gimple_stmt_iterator gsi = gsi_for_stmt (stmt); >gsi_replace (, vec_stmt, false); > > - vect_finish_stmt_generation_1 (stmt, vec_stmt); > + return vect_finish_stmt_generation_1 (stmt, vec_stmt); > } > > -/* Function vect_finish_stmt_generation. > - > - Insert a new stmt. */ > +/* Add VEC_STMT to the vectorized implementation of STMT and insert it > + before *GSI.
[12/46] Make vect_finish_stmt_generation return a stmt_vec_info
This patch makes vect_finish_replace_stmt and vect_finish_stmt_generation return the stmt_vec_info for the vectorised statement, so that the caller doesn't need a separate vinfo_for_stmt to get at it. This involved changing the structure of the statement-generating loops so that they use narrow scopes for the vectorised gimple statements and use the existing (wider) scopes for the associated stmt_vec_infos. This helps with gimple stmt->stmt_vec_info changes further down the line. The way we do this generation is another area ripe for clean-up, but that's too much of a rabbit-hole for this series. 2018-07-24 Richard Sandiford gcc/ * tree-vectorizer.h (vect_finish_replace_stmt): Return a stmt_vec_info (vect_finish_stmt_generation): Likewise. * tree-vect-stmts.c (vect_finish_stmt_generation_1): Likewise. (vect_finish_replace_stmt, vect_finish_stmt_generation): Likewise. (vect_build_gather_load_calls): Use the return value of the above functions instead of a separate call to vinfo_for_stmt. Use narrow scopes for the input gimple stmt and wider scopes for the associated stmt_vec_info. Use vec_info::lookup_def when setting these stmt_vec_infos from an SSA_NAME definition. (vectorizable_bswap, vectorizable_call, vectorizable_simd_clone_call) (vect_create_vectorized_demotion_stmts, vectorizable_conversion) (vectorizable_assignment, vectorizable_shift, vectorizable_operation) (vectorizable_store, vectorizable_load, vectorizable_condition) (vectorizable_comparison): Likewise. * tree-vect-loop.c (vectorize_fold_left_reduction): Likewise. (vectorizable_reduction): Likewise. Index: gcc/tree-vectorizer.h === --- gcc/tree-vectorizer.h 2018-07-24 10:22:37.257248166 +0100 +++ gcc/tree-vectorizer.h 2018-07-24 10:22:40.725217371 +0100 @@ -1548,9 +1548,9 @@ extern void free_stmt_vec_info (gimple * extern unsigned record_stmt_cost (stmt_vector_for_cost *, int, enum vect_cost_for_stmt, stmt_vec_info, int, enum vect_cost_model_location); -extern void vect_finish_replace_stmt (gimple *, gimple *); -extern void vect_finish_stmt_generation (gimple *, gimple *, - gimple_stmt_iterator *); +extern stmt_vec_info vect_finish_replace_stmt (gimple *, gimple *); +extern stmt_vec_info vect_finish_stmt_generation (gimple *, gimple *, + gimple_stmt_iterator *); extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info); extern tree vect_get_store_rhs (gimple *); extern tree vect_get_vec_def_for_operand_1 (gimple *, enum vect_def_type); Index: gcc/tree-vect-stmts.c === --- gcc/tree-vect-stmts.c 2018-07-24 10:22:37.257248166 +0100 +++ gcc/tree-vect-stmts.c 2018-07-24 10:22:40.725217371 +0100 @@ -1729,15 +1729,15 @@ vect_get_vec_defs (tree op0, tree op1, g /* Helper function called by vect_finish_replace_stmt and vect_finish_stmt_generation. Set the location of the new - statement and create a stmt_vec_info for it. */ + statement and create and return a stmt_vec_info for it. */ -static void +static stmt_vec_info vect_finish_stmt_generation_1 (gimple *stmt, gimple *vec_stmt) { stmt_vec_info stmt_info = vinfo_for_stmt (stmt); vec_info *vinfo = stmt_info->vinfo; - vinfo->add_stmt (vec_stmt); + stmt_vec_info vec_stmt_info = vinfo->add_stmt (vec_stmt); if (dump_enabled_p ()) { @@ -1753,12 +1753,15 @@ vect_finish_stmt_generation_1 (gimple *s int lp_nr = lookup_stmt_eh_lp (stmt); if (lp_nr != 0 && stmt_could_throw_p (vec_stmt)) add_stmt_to_eh_lp (vec_stmt, lp_nr); + + return vec_stmt_info; } /* Replace the scalar statement STMT with a new vector statement VEC_STMT, - which sets the same scalar result as STMT did. */ + which sets the same scalar result as STMT did. Create and return a + stmt_vec_info for VEC_STMT. */ -void +stmt_vec_info vect_finish_replace_stmt (gimple *stmt, gimple *vec_stmt) { gcc_assert (gimple_get_lhs (stmt) == gimple_get_lhs (vec_stmt)); @@ -1766,14 +1769,13 @@ vect_finish_replace_stmt (gimple *stmt, gimple_stmt_iterator gsi = gsi_for_stmt (stmt); gsi_replace (, vec_stmt, false); - vect_finish_stmt_generation_1 (stmt, vec_stmt); + return vect_finish_stmt_generation_1 (stmt, vec_stmt); } -/* Function vect_finish_stmt_generation. - - Insert a new stmt. */ +/* Add VEC_STMT to the vectorized implementation of STMT and insert it + before *GSI. Create and return a stmt_vec_info for VEC_STMT. */ -void +stmt_vec_info vect_finish_stmt_generation (gimple *stmt, gimple *vec_stmt, gimple_stmt_iterator *gsi) { @@ -1806,7 +1808,7 @@ vect_finish_stmt_generation (gimple *stm