https://gcc.gnu.org/g:6b41a6a73ef8f39ac913c0224a2c23b67f2a0665

commit r17-5090-g6b41a6a73ef8f39ac913c0224a2c23b67f2a0665
Author: Richard Biener <[email protected]>
Date:   Mon Oct 12 10:05:58 2026 +0200

    tree-optimization/127811 - ICE with external vector def from control stmt
    
    When an external vector def defined by a control statement is scheduled
    we correctly place it.  But when we later re-run the placing during
    transform we look at the actual vector def and assert before we are
    eventually adjusting the location again.  Mind we cannot simply re-use
    the computed schedule, so adjust the assert to treat externs the same
    as !last_stmt.
    
            PR tree-optimization/127811
            * tree-vect-slp.cc (vect_schedule_slp_node): Allow extern
            last_stmt during transform.
    
            * g++.dg/vect/pr127811.cc: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/vect/pr127811.cc | 15 +++++++++++++++
 gcc/tree-vect-slp.cc                  |  7 ++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr127811.cc 
b/gcc/testsuite/g++.dg/vect/pr127811.cc
new file mode 100644
index 000000000000..8d4efdb0057a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr127811.cc
@@ -0,0 +1,15 @@
+// { dg-do compile }
+
+#define vector(type, elm) type __attribute__ ((vector_size (sizeof(type)*elm)))
+
+typedef vector(float,4) v4float;
+v4float get (void);
+struct s1 { ~s1(); };
+
+void
+f (v4float *r)
+{
+  s1 guard;
+  v4float v = get ();
+  *r =  (v4float) { v[0] + 1, v[1] + 1, v[2] + 1, v[3] + 1 };
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 00ed4d3fec14..558517819f54 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -12376,7 +12376,12 @@ vect_schedule_slp_node (vec_info *vinfo,
       /* We split regions to vectorize at control altering stmts
         with a definition so this can only be an external.  */
       gcc_checking_assert (!last_stmt
-                          || !is_ctrl_altering_stmt (last_stmt));
+                          || !is_ctrl_altering_stmt (last_stmt)
+                          /* Existing vector defs can be external, we will
+                             adjust the insertion point below.  */
+                          || (!place_only
+                              && dominated_by_p (CDI_DOMINATORS, vinfo->bbs[0],
+                                                 gimple_bb (last_stmt))));
 
       if (is_a <bb_vec_info> (vinfo)
          && !SLP_TREE_PERMUTE_P (node)

Reply via email to