https://gcc.gnu.org/g:9ab2b161c7cb19d85f124ec2d30bec89169a4e05

commit r17-5200-g9ab2b161c7cb19d85f124ec2d30bec89169a4e05
Author: Richard Biener <[email protected]>
Date:   Wed Oct 14 14:52:43 2026 +0200

    tree-optimization/127811 - revise previous fix for SLP scheduling
    
    With -fno-trapping-math we still attempt to inseret after the
    throwing external vector def.  Instead of adjusting the assert
    make sure to clear last_stmt when that is external so we
    consistently insert at region boundary.
    
            PR tree-optimization/127811
            * tree-vect-slp.cc (vect_schedule_slp_node): Revert last fix.
            Instead NULL last_stmt for external defs.
    
            * g++.dg/vect/pr127811-2.cc: New testcase.

Diff:
---
 gcc/testsuite/g++.dg/vect/pr127811-2.cc | 16 ++++++++++++++++
 gcc/tree-vect-slp.cc                    | 16 ++++++++++------
 2 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr127811-2.cc 
b/gcc/testsuite/g++.dg/vect/pr127811-2.cc
new file mode 100644
index 000000000000..4e2d6c623f54
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr127811-2.cc
@@ -0,0 +1,16 @@
+// { dg-do compile }
+// { dg-additional-options "-fno-trapping-math" }
+
+#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 558517819f54..6e8047f2f4c8 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -12373,15 +12373,19 @@ vect_schedule_slp_node (vec_info *vinfo,
              }
          }
 
+      /* When we face existing vector defs that are external, make sure
+        to insert at region boundary.  */
+      if (last_stmt
+         && is_a <bb_vec_info> (vinfo)
+         && vinfo->bbs[0] != gimple_bb (last_stmt)
+         && dominated_by_p (CDI_DOMINATORS, vinfo->bbs[0],
+                            gimple_bb (last_stmt)))
+       last_stmt = NULL;
+
       /* 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)
-                          /* 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))));
+                          || !is_ctrl_altering_stmt (last_stmt));
 
       if (is_a <bb_vec_info> (vinfo)
          && !SLP_TREE_PERMUTE_P (node)

Reply via email to