https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102847
--- Comment #8 from Kewen Lin <linkw at gcc dot gnu.org> --- (In reply to Richard Biener from comment #5) > diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c > index 9cbc1af4cc9..8f527452bd0 100644 > --- a/gcc/tree-vect-stmts.c > +++ b/gcc/tree-vect-stmts.c > @@ -1191,6 +1191,13 @@ vect_model_load_cost (vec_info *vinfo, > ncopies * assumed_nunits, > scalar_load, stmt_info, 0, vect_body); > } > + else if (memory_access_type == VMAT_INVARIANT) > + { > + /* Invariant loads will ideally be hoisted and splat to a vector. */ > + prologue_cost += record_stmt_cost (cost_vec, 1, > + scalar_to_vec, stmt_info, 0, > + vect_prologue); > + } > else > vect_get_load_cost (vinfo, stmt_info, ncopies, > alignment_support_scheme, misalignment, first_stmt_p, > > should fix that in a better way. Nice, I confirmed this change can fix the issue. Thanks! For costing, it seems we need one more scalar_load costing for vect_prologue? or here we aggressively consider scalar_to_vec is also for load_and_splat?