https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110742
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rsandifo at gcc dot gnu.org --- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> --- So we have those external def nodes for existing vectors in the IL. Obviously we cannot change the layout of those - where can we specify that? I see is_compatible_layout or change_layout_cost. But start_choosing_layouts already assigns layout 0 to it where I thought this would effectively prevent changes? Oddly in forward_pass we first have partition.layout == 0 && layout_i == 0 but still do stuff. $38 = 0x3d8f690 = {{node_begin = 0, node_end = 1, layout = 0, in_degree = 0, out_degree = 1}, { node_begin = 1, node_end = 2, layout = 1, in_degree = 1, out_degree = 0}, {node_begin = 2, node_end = 3, layout = 2, in_degree = 0, out_degree = 0}} later we ask if changing layout from 0 to 1 is OK. I suppose the bug is in get_result_with_layout itself which assumes changing vect_constant_def/vect_external_def is fine and thus pushes the edge permute to the node? I wonder if I fix that say with the following, if I also need to adjust costs somewhere? diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 693621ca990..1d79c77e8ce 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -5198,7 +5198,10 @@ vect_optimize_slp_pass::get_result_with_layout (slp_tree node, return result; if (SLP_TREE_DEF_TYPE (node) == vect_constant_def - || SLP_TREE_DEF_TYPE (node) == vect_external_def) + || (SLP_TREE_DEF_TYPE (node) == vect_external_def + && (to_layout_i == 0 + /* We can't permute vector defs. */ + || SLP_TREE_VEC_DEFS (node).is_empty ()))) { /* If the vector is uniform or unchanged, there's nothing to do. */ if (to_layout_i == 0 || vect_slp_tree_uniform_p (node)) I'll also note that we do /* Handle externals and constants optimistically throughout. But treat existing vectors as fixed since we do not handle permuting them. */ unsigned int node_i = m_partitioned_nodes[rpo_i]; auto &vertex = m_vertices[node_i]; if ((SLP_TREE_DEF_TYPE (vertex.node) == vect_external_def && !SLP_TREE_VEC_DEFS (vertex.node).exists ()) || SLP_TREE_DEF_TYPE (vertex.node) == vect_constant_def) vertex.partition = -1; in create_partitions (). I'm testing the above change now.