[gcc r17-3282] tree-optimization/126852 - verify SLP schedule also for PHIs

Richard Biener via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:6a000bf53e6f42cff3774822227f47e39d2b76d5

commit r17-3282-g6a000bf53e6f42cff3774822227f47e39d2b76d5
Author: Richard Biener <[email protected]>
Date:   Fri Aug 14 10:57:17 2026 +0200

    tree-optimization/126852 - verify SLP schedule also for PHIs
    
    We have to verify the PHI argument nodes insertion place dominates
    the PHI argument edge sources.
    
            PR tree-optimization/126852
            * tree-vect-slp.cc (vect_schedule_slp_node): Verify schedule
            for PHIs.
    
            * gcc.dg/vect/bb-slp-pr126852.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr126852.c | 25 +++++++++++++++++++++++++
 gcc/tree-vect-slp.cc                        | 10 ++++++++++
 2 files changed, 35 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr126852.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr126852.c
new file mode 100644
index 000000000000..5391a08d3144
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr126852.c
@@ -0,0 +1,25 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-O3 -fno-tree-pre" } */
+/* { dg-additional-options "-mavx2" { target avx2 } } */
+
+int a;
+long b, c;
+__attribute__((noinline)) int d() {
+  a = 0;
+  return 0;
+}
+void e(char f, char g, long h, long i) {
+  char j;
+k:
+  do {
+    j = 2 * f;
+    if (!g)
+      return;
+    d();
+    if (g << g)
+      goto k;
+    unsigned long m = b;
+    long n = m >> 8;
+    c = n + 2088470516281635866 * i + h * h + 7017580219 * i;
+  } while (j < f + 2);
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index d1bf3499eb7e..bda7ae679e55 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -12117,6 +12117,16 @@ vect_schedule_slp_node (vec_info *vinfo,
     {
       /* For PHI node vectorization we do not use the insertion iterator.  */
       last_stmt = SLP_TREE_SCALAR_STMTS (node)[0]->stmt;
+      if (place_only)
+	FOR_EACH_VEC_ELT (SLP_TREE_CHILDREN (node), i, child)
+	  {
+	    if (child->si
+		&& !dominated_by_p (CDI_DOMINATORS,
+				    gimple_phi_arg_edge
+				      (as_a <gphi *> (last_stmt), i)->src,
+				    gimple_bb (child->si)))
+	      return false;
+	  }
       si = gsi_none ();
     }
   else
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.