https://gcc.gnu.org/g:d0b1eaaf0ba4b9e6fd2b18ef597bde3eb7bd018b
commit d0b1eaaf0ba4b9e6fd2b18ef597bde3eb7bd018b Author: Richard Biener <rguent...@suse.de> Date: Thu Mar 7 15:13:33 2024 +0100 Handle unused-only-live stmts in SLP discovery The following adds SLP discovery for roots that are only live but otherwise unused. * tree-vect-slp.cc (vect_analyze_slp): Analyze SLP for live but otherwise unused defs. Diff: --- gcc/tree-vect-slp.cc | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 6cc544057115..3138a815da7a 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -3985,6 +3985,40 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size) saved_stmts.release (); } } + + if (param_vect_single_lane_slp != 0) + { + /* Make sure to vectorize only-live stmts, usually inductions. */ + for (edge e : get_loop_exit_edges (LOOP_VINFO_LOOP (loop_vinfo))) + for (auto gsi = gsi_start_phis (e->dest); !gsi_end_p (gsi); + gsi_next (&gsi)) + { + gphi *lc_phi = *gsi; + tree def = gimple_phi_arg_def_from_edge (lc_phi, e); + stmt_vec_info stmt_info; + if (TREE_CODE (def) == SSA_NAME + && !virtual_operand_p (def) + && (stmt_info = loop_vinfo->lookup_def (def)) + && STMT_VINFO_RELEVANT (stmt_info) == vect_used_only_live + && STMT_VINFO_LIVE_P (stmt_info) + && (STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def + || (STMT_VINFO_DEF_TYPE (stmt_info) == vect_internal_def + && STMT_VINFO_REDUC_IDX (stmt_info) == -1))) + { + vec<stmt_vec_info> stmts; + vec<stmt_vec_info> roots = vNULL; + vec<tree> remain = vNULL; + stmts.create (1); + stmts.quick_push (vect_stmt_to_vectorize (stmt_info)); + bool res = vect_build_slp_instance (vinfo, + slp_inst_kind_reduc_group, + stmts, roots, remain, + max_tree_size, &limit, + bst_map, NULL); + gcc_assert (res); + } + } + } } hash_set<slp_tree> visited_patterns;