https://gcc.gnu.org/g:5fd00b0f19c4c3183f0e897e57432967bb6fe326
commit r17-5481-g5fd00b0f19c4c3183f0e897e57432967bb6fe326 Author: Robin Dapp <[email protected]> Date: Fri Sep 18 10:03:17 2026 +0200 vect: Cost niter assumption. This patch adjusts niter-assumption costing. Instead of just one vector statements, it conservatively uses the number statements involved in the assumption tree. gcc/ChangeLog: * tree-vect-loop.cc (vect_estimate_min_profitable_iters): Adjust niter assumption costing. Diff: --- gcc/tree-vect-loop.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index b879de8d44c5..7ed3f58bf238 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -4134,8 +4134,23 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo, /* Requires loop versioning with niter checks. */ if (LOOP_REQUIRES_VERSIONING_FOR_NITERS (loop_vinfo)) { - /* FIXME: Make cost depend on complexity of individual check. */ - (void) add_stmt_cost (target_cost_data, 1, vector_stmt, + tree assum = LOOP_VINFO_NITERS_ASSUMPTIONS (loop_vinfo); + + /* Count all involved statements in the assumption. + ??? This might over-count in case we CSE later. */ + auto count_stmts = [] (tree *t, int *walk, void *nstmts) -> tree + { + if (!EXPR_P (*t) || is_gimple_val (*t)) + *walk = 0; + else + (*(int *) nstmts)++; + return NULL_TREE; + }; + + int nstmts = 0; + walk_tree_without_duplicates (&assum, count_stmts, &nstmts); + + (void) add_stmt_cost (target_cost_data, nstmts, scalar_stmt, NULL, NULL, NULL_TREE, 0, vect_prologue); if (dump_enabled_p ()) dump_printf (MSG_NOTE,
