]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/125080 - fix SLP scalar stmt coverage for instance roots
authorRichard Biener <rguenther@suse.de>
Wed, 29 Apr 2026 12:28:49 +0000 (14:28 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 29 Apr 2026 14:00:40 +0000 (16:00 +0200)
Even instance roots can be mentioned in externs of other instances
and thus have to be kept scalar.  Consider that.

PR tree-optimization/125080
* tree-vect-slp.cc (vect_bb_slp_mark_stmts_vectorized): Only
add instance root stmts to scalar coverage if they do not
appear in externs.

* gcc.dg/torture/pr125080.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr125080.c [new file with mode: 0644]
gcc/tree-vect-slp.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr125080.c b/gcc/testsuite/gcc.dg/torture/pr125080.c
new file mode 100644 (file)
index 0000000..8ab5819
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-ffast-math" } */
+
+struct S { double a, b, c, d, e, f; };
+void g(struct S *s, double *p, double *q, long n)
+{
+  for (long i; i < n; ++i) {
+    s->b = s->c * p[i];
+    s->a = s->f * s->d + s->b;
+    q[i] += s->f;
+    if (s->e) s->a = s->e;
+  }
+}
index 6b297464bbf9b96a683a1b6d41e085c489cd868d..00bb891fccb252a2db3aa8170b4d7f2ab99c22dc 100644 (file)
@@ -3525,7 +3525,8 @@ vect_bb_slp_mark_stmts_vectorized (bb_vec_info vinfo)
   for (auto instance : BB_VINFO_SLP_INSTANCES (vinfo))
     {
       for (auto stmt : SLP_INSTANCE_ROOT_STMTS (instance))
-       STMT_SLP_TYPE (stmt) = pure_slp;
+       if (!scalar_stmts_in_externs.contains (stmt))
+         STMT_SLP_TYPE (stmt) = pure_slp;
       auto_vec<stmt_vec_info> worklist;
       for (auto stmt : SLP_TREE_SCALAR_STMTS (SLP_INSTANCE_TREE (instance)))
        {