From: Richard Biener Date: Thu, 7 Mar 2024 14:13:33 +0000 (+0100) Subject: Handle unused-only-live stmts in SLP discovery X-Git-Tag: basepoints/gcc-16~6086 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5df05de3d917754274cadb7d006b2011f93f4f7b;p=thirdparty%2Fgcc.git Handle unused-only-live stmts in SLP discovery The following adds SLP discovery for roots that are only live but otherwise unused. These are usually inductions. This allows a few more testcases to be handled fully with SLP, for example gcc.dg/vect/no-scevccp-pr86725-1.c * tree-vect-slp.cc (vect_analyze_slp): Analyze SLP for live but otherwise unused defs. --- diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index d35e0609174..b6839c7707b 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -4681,6 +4681,36 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size) saved_stmts.release (); } } + + /* 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 stmts; + vec roots = vNULL; + vec remain = vNULL; + stmts.create (1); + stmts.quick_push (vect_stmt_to_vectorize (stmt_info)); + vect_build_slp_instance (vinfo, + slp_inst_kind_reduc_group, + stmts, roots, remain, + max_tree_size, &limit, + bst_map, NULL); + } + } } hash_set visited_patterns;