https://gcc.gnu.org/g:a74a0db75acd5118d8fd89e0f0fc4f2cd55e9317

commit r16-6534-ga74a0db75acd5118d8fd89e0f0fc4f2cd55e9317
Author: Richard Biener <[email protected]>
Date:   Tue Jan 6 13:25:10 2026 +0100

    tree-optimization/123221 - ICE with conversion reduction
    
    The following avoids ICEing with a reduction only consisting of
    noop-conversions.
    
            PR tree-optimization/123221
            * tree-vect-loop.cc (vectorizable_reduction): When we did not
            find the non-conversion reduction operation, bail.
    
            * gcc.dg/vect/vect-pr123221.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/vect-pr123221.c | 14 ++++++++++++++
 gcc/tree-vect-loop.cc                     |  7 +++++++
 2 files changed, 21 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr123221.c 
b/gcc/testsuite/gcc.dg/vect/vect-pr123221.c
new file mode 100644
index 000000000000..642517926d0d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-pr123221.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-fno-tree-pre" } */
+
+int a, d;
+struct {
+  char b;
+} c;
+int main()
+{
+  int f;
+  for (; d; d++)
+    c.b = f = a ? c.b : 0;
+  return 0;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index a82949745e84..994d1a3ee749 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7123,6 +7123,13 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
        }
       reduc_chain_length++;
     }
+  if (!slp_for_stmt_info)
+    {
+      if (dump_enabled_p ())
+       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                        "only noop-conversions in the reduction chain.\n");
+      return false;
+    }
   stmt_info = SLP_TREE_REPRESENTATIVE (slp_for_stmt_info);
 
   /* PHIs should not participate in patterns.  */

Reply via email to