https://gcc.gnu.org/g:2027574bacf4fb665a4cb42a33608e169363b39f

commit r16-3412-g2027574bacf4fb665a4cb42a33608e169363b39f
Author: Richard Biener <rguent...@suse.de>
Date:   Wed Aug 27 09:53:49 2025 +0200

    tree-optimization/121686 - failed SLP discovery for live recurrence
    
    The following adjusts the SLP build for only-live stmts to not
    only consider vect_induction_def and vect_internal_def that are
    not part of a reduction but instead consider all non-reduction
    defs that are not part of a reduction, specifically in this case
    a recurrence def.  This is also a missed optimization on the
    gcc-15 branch (but IMO a very minor one).
    
            PR tree-optimization/121686
            * tree-vect-slp.cc (vect_analyze_slp): Consider all only-live
            non-reduction defs for discovery.
    
            * gcc.dg/vect/pr121686.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr121686.c | 32 ++++++++++++++++++++++++++++++++
 gcc/tree-vect-slp.cc                 |  5 ++---
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr121686.c 
b/gcc/testsuite/gcc.dg/vect/pr121686.c
new file mode 100644
index 000000000000..5a9284c3d310
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr121686.c
@@ -0,0 +1,32 @@
+/* { dg-additional-options "-O3" } */
+
+#include "tree-vect.h"
+
+signed char a, b, c, f;
+int d, e, g, h;
+
+int main()
+{
+  int j, k;
+  signed char m;
+  check_vect ();
+  while (f < 4) {
+    k = b = 3;
+    for (; b >= 0; b--) {
+      j = a < 0 ? a : a >> h;
+      g = k;
+      e = j;
+      k = 0;
+      while (1) {
+        if (j)
+          break;
+        k = f == 0;
+        break;
+      }
+    }
+    m = g * 87;
+    if (m < 70)
+      __builtin_abort();
+    return 0;
+  }
+}
diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index 2df9d2b3c6d2..86508e22f49a 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -5312,9 +5312,8 @@ vect_analyze_slp (vec_info *vinfo, unsigned max_tree_size,
                && ((stmt_info = vect_stmt_to_vectorize (stmt_info)), true)
                && STMT_VINFO_RELEVANT (stmt_info) == vect_used_only_live
                && STMT_VINFO_LIVE_P (stmt_info)
-               && (STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def
-                   || (STMT_VINFO_DEF_TYPE (stmt_info) == vect_internal_def
-                       && STMT_VINFO_REDUC_IDX (stmt_info) == -1)))
+               && !VECTORIZABLE_CYCLE_DEF (STMT_VINFO_DEF_TYPE (stmt_info))
+               && STMT_VINFO_REDUC_IDX (stmt_info) == -1)
              {
                vec<stmt_vec_info> stmts;
                vec<stmt_vec_info> roots = vNULL;

Reply via email to