https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106081
--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to rsand...@gcc.gnu.org from comment #10) > (In reply to Richard Biener from comment #9) [...] > > The following elides the unnecessary permutation for this special case > > (but not the general case): > > > > diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc > > index e4430248ab5..e9048a61891 100644 > > --- a/gcc/tree-vect-slp.cc > > +++ b/gcc/tree-vect-slp.cc > > @@ -4389,6 +4389,19 @@ vect_optimize_slp_pass::change_layout_cost (slp_tree > > node, > > if (from_layout_i == to_layout_i) > > return 0; > > > > + /* When there's a uniform load permutation permutating that in any > > + way is free. */ > > + if (SLP_TREE_LOAD_PERMUTATION (node).exists ()) > > + { > > + unsigned l = SLP_TREE_LOAD_PERMUTATION (node)[0]; > > + unsigned i; > > + for (i = 1; i < SLP_TREE_LOAD_PERMUTATION (node).length (); ++i) > > + if (SLP_TREE_LOAD_PERMUTATION (node)[i] != l) > > + break; > > + if (i == SLP_TREE_LOAD_PERMUTATION (node).length ()) > > + return 0; > > + } > > + > > auto_vec<slp_tree, 1> children (1); > > children.quick_push (node); > > auto_lane_permutation_t perm (SLP_TREE_LANES (node)); > > > > I'm not sure this is the correct place to factor in cost savings > > materialization would give. Is it? > Yeah, I think so. The patch LGTM. I don't know if it's worth > caching the “all the same element” result, but probably not. Yeah, I thought of changing the load_permutation representation to vec_perm_indices but then as I consider merging lane and load permutes that would be wrong step. I've thought of generalizing the above but then change_layout_cost is always positive but for example when doing { 3, 2, 1, 0 } ontop an existing load permutation of { 3, 2, 1, 0 } the cost should be negative? Anyway, going to test the above patch.