https://gcc.gnu.org/g:f5af5512d34fbf5c30b1f450fb199cf73515f4df

commit r17-5398-gf5af5512d34fbf5c30b1f450fb199cf73515f4df
Author: Richard Biener <[email protected]>
Date:   Tue Oct 20 10:21:55 2026 +0200

    tree-optimization/128013 - SSA corruption with SLP of abnormals
    
    We have to execlude existing abnormal vector defs from SLP processing
    as we'll introduce new uses that may prevent coalescing.
    
            PR tree-optimization/128013
            * tree-vect-slp.cc (vect_build_slp_tree_3): Exclude existing
            vector defs that take part in abnormal coalescing.
    
            * gcc.dg/vect/bb-slp-pr128013.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/bb-slp-pr128013.c | 61 +++++++++++++++++++++++++++++
 gcc/tree-vect-slp.cc                        |  1 +
 2 files changed, 62 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr128013.c 
b/gcc/testsuite/gcc.dg/vect/bb-slp-pr128013.c
new file mode 100644
index 000000000000..4cd8179f6aaa
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr128013.c
@@ -0,0 +1,61 @@
+/* { dg-do compile } */
+
+typedef int v4si __attribute__ ((vector_size (16)));
+typedef float v4sf __attribute__ ((vector_size (16)));
+extern int rt (void) __attribute__ ((returns_twice));
+extern void bar (void);
+extern void use (v4si);
+extern void usef (v4sf);
+
+/* The vector store goes before the last scalar store.  */
+
+void
+f1 (int *out, v4si v, int c)
+{
+  int a0 = v[0], a1 = v[1], a2 = v[2], a3 = v[3];
+  bar ();
+  v = v * 3;
+  if (c)
+    {
+      out[0] = a0;
+      out[1] = a1;
+      out[2] = a2;
+      out[3] = a3;
+    }
+  bar ();
+  rt ();
+  use (v);
+}
+
+void
+f2 (float *out, v4sf v)
+{
+  float a0 = v[0], a1 = v[1], a2 = v[2], a3 = v[3];
+  bar ();
+  v = v * 3;
+  bar ();
+  out[0] = a0 + 1;
+  out[1] = a1 + 2;
+  out[2] = a2 + 3;
+  out[3] = a3 + 4;
+  bar ();
+  rt ();
+  usef (v);
+}
+
+/* The reduction code goes at the root stmt.  */
+
+int
+f3 (v4si v, int c)
+{
+  int a0 = v[0], a1 = v[1], a2 = v[2], a3 = v[3];
+  int r = 0;
+  bar ();
+  v = v * 3;
+  if (c)
+    r = a0 + a1 + a2 + a3;
+  bar ();
+  rt ();
+  use (v);
+  return r;
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 6e8047f2f4c8..4b0585369f90 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -1329,6 +1329,7 @@ vect_build_slp_tree_3 (vec_info *vinfo, 
vec<stmt_vec_info> stmts,
          tree vec = TREE_OPERAND (gimple_assign_rhs1 (stmt), 0);
          if (!is_a <bb_vec_info> (vinfo)
              || TREE_CODE (vec) != SSA_NAME
+             || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (vec)
              /* When the element types are not compatible we pun the
                 source to the target vectype which requires equal size.  */
              || ((!VECTOR_TYPE_P (TREE_TYPE (vec))

Reply via email to