https://gcc.gnu.org/g:898e3e95a6acf542baf03be95ce5bf7b3ad04276

commit r15-3547-g898e3e95a6acf542baf03be95ce5bf7b3ad04276
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Sep 9 11:51:24 2024 +0200

    tree-optimization/116647 - wrong classified double reduction
    
    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.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr116647.c          | 22 ++++++++++++++++++++++
 gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c |  2 +-
 gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c |  2 +-
 gcc/tree-vect-loop.cc                            |  3 ++-
 4 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/torture/pr116647.c 
b/gcc/testsuite/gcc.dg/torture/pr116647.c
new file mode 100644
index 000000000000..2b5cc3486900
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr116647.c
@@ -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;
+}
diff --git a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c 
b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c
index b208c1a2d615..66185a9483ba 100644
--- a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c
+++ b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c
@@ -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" } } */
diff --git a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c 
b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c
index d995c9b30fe2..6ada0a10cb36 100644
--- a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c
+++ b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c
@@ -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" } } */
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index a879a13bbf0c..65d7ed51067e 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -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,

Reply via email to