]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/121754 - ICE with vect_reduc_type and nested cycle
authorRichard Biener <rguenther@suse.de>
Tue, 2 Sep 2025 07:50:14 +0000 (09:50 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 2 Sep 2025 10:51:12 +0000 (12:51 +0200)
The reduction guard isn't correct, STMT_VINFO_REDUC_DEF also exists
for nested cycles not part of reductions but there's no reduction
info for them.

PR tree-optimization/121754
* tree-vectorizer.h (vect_reduc_type): Simplify to not ICE
on nested cycles.

* gcc.dg/vect/pr121754.c: New testcase.
* gcc.target/aarch64/vect-pr121754.c: Likewise.

gcc/testsuite/gcc.dg/vect/pr121754.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/vect-pr121754.c [new file with mode: 0644]
gcc/tree-vectorizer.h

diff --git a/gcc/testsuite/gcc.dg/vect/pr121754.c b/gcc/testsuite/gcc.dg/vect/pr121754.c
new file mode 100644 (file)
index 0000000..775abda
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+
+float a;
+void
+fn1 (int b)
+{
+  for (; b < 10; b++)
+    {
+      a = 01.;
+      for (int c = 0; c < 2000; c++)
+        a *= 0.99;
+    }
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/vect-pr121754.c b/gcc/testsuite/gcc.target/aarch64/vect-pr121754.c
new file mode 100644 (file)
index 0000000..8b6a757
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ftree-vectorize -mcpu=neoverse-v2" } */
+
+float a;
+void
+fn1 (int b)
+{
+  for (; b < 10; b++)
+    {
+      a = 01.;
+      for (int c = 0; c < 2000; c++)
+        a *= 0.99;
+    }
+}
index 87ffe497008a2ba7aa4606b6c802695a2ac4673e..df805c6ade92d5aa7043310739d2dbfff2b236aa 100644 (file)
@@ -2923,13 +2923,9 @@ vect_reduc_type (vec_info *vinfo, slp_tree node)
 {
   if (loop_vec_info loop_vinfo = dyn_cast<loop_vec_info> (vinfo))
     {
-      stmt_vec_info stmt_info = SLP_TREE_REPRESENTATIVE (node);
-      if (STMT_VINFO_REDUC_DEF (stmt_info))
-       {
-         vect_reduc_info reduc_info
-           = info_for_reduction (loop_vinfo, node);
-         return int (VECT_REDUC_INFO_TYPE (reduc_info));
-       }
+      vect_reduc_info reduc_info = info_for_reduction (loop_vinfo, node);
+      if (reduc_info)
+       return int (VECT_REDUC_INFO_TYPE (reduc_info));
     }
   return -1;
 }