]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/116647 - wrong classified double reduction
authorRichard Biener <rguenther@suse.de>
Mon, 9 Sep 2024 09:51:24 +0000 (11:51 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 9 Sep 2024 10:59:38 +0000 (12:59 +0200)
The following avoids classifying a double reduction that's not
actually a reduction in the outer loop (because its value isn't
used outside of the outer loop).  This avoids us ICEing on the
unexpected stmt/SLP node arrangement.

PR tree-optimization/116647
* tree-vect-loop.cc (vect_is_simple_reduction): Add missing
check to double reduction detection.

* gcc.dg/torture/pr116647.c: New testcase.
* gcc.dg/vect/no-scevccp-pr86725-2.c: Adjust expected pattern.
* gcc.dg/vect/no-scevccp-pr86725-4.c: Likewise.

gcc/testsuite/gcc.dg/torture/pr116647.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c
gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr116647.c b/gcc/testsuite/gcc.dg/torture/pr116647.c
new file mode 100644 (file)
index 0000000..2b5cc34
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+
+int a;
+char b;
+long c, d, e;
+unsigned long f;
+long g() {
+  if (a <= 0)
+    return 1;
+  for (; d; d++) {
+    e = 0;
+    for (; e < a; e++) {
+      unsigned long h = 0;
+      switch (b)
+      case 2:
+        if (e)
+          h = 5;
+      c += h;
+    }
+  }
+  c /= f;
+}
index b208c1a2d6159d7dc629bc2bba21df1eb2771b18..66185a9483ba1401700480c6790bce5b43162920 100644 (file)
@@ -19,5 +19,5 @@ nr (int xe)
   return xe;
 }
 
-/* { dg-final { scan-tree-dump "reduction used in loop" "vect" { target vect_int } } } */
+/* { dg-final { scan-tree-dump "Unknown def-use cycle pattern" "vect" { target vect_int } } } */
 /* { dg-final { scan-tree-dump-not "OUTER LOOP VECTORIZED" "vect" } } */
index d995c9b30fe2f65d465c7de8f4dea78124f168d1..6ada0a10cb367ce95a29ed14b4af5ba09949bcf2 100644 (file)
@@ -19,5 +19,5 @@ nr (unsigned int xe, unsigned int qqn)
   return xe;
 }
 
-/* { dg-final { scan-tree-dump "reduction used in loop" "vect" { target vect_int } } } */
+/* { dg-final { scan-tree-dump "Unknown def-use cycle pattern" "vect" { target vect_int } } } */
 /* { dg-final { scan-tree-dump-not "OUTER LOOP VECTORIZED" "vect" } } */
index a879a13bbf0c2c074bb62751ddea1c45ce5f6c7e..65d7ed51067e585830c7a1e2509abfe72288bd58 100644 (file)
@@ -4325,7 +4325,8 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info,
          && is_a <gphi *> (phi_use_stmt)
          && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt))
          && (op1 == PHI_ARG_DEF_FROM_EDGE (phi_use_stmt,
-                                           loop_latch_edge (loop->inner))))
+                                           loop_latch_edge (loop->inner)))
+         && lcphis.length () == 1)
         {
           if (dump_enabled_p ())
             report_vect_op (MSG_NOTE, def_stmt,