The following adds an early out for unsupported reduction operations
to avoid ICEing when the assumption that the GIMPLE stmt operand
number matches the SLP operand number breaks, as is for .CLZ with
two operands.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

        PR tree-optimization/126457
        * tree-vect-loop.cc (vectorizable_reduction): Reject
        operations where not all operands correspond to a SLP
        child early.

        * gcc.dg/vect/vect-pr126457.c: New testcase.
---
 gcc/testsuite/gcc.dg/vect/vect-pr126457.c | 16 ++++++++++++++++
 gcc/tree-vect-loop.cc                     | 10 ++++++++++
 2 files changed, 26 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/vect/vect-pr126457.c

diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr126457.c 
b/gcc/testsuite/gcc.dg/vect/vect-pr126457.c
new file mode 100644
index 00000000000..be441b30426
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-pr126457.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+
+int g6, g24;
+_Bool f18_c6;
+void f18()
+{
+    int a1;
+    int bb16 = 607229;
+lbl_sw5:
+    bb16 = __builtin_clz(bb16);
+    f18_c6 = a1;
+    a1 = g24;
+    if (f18_c6) goto lbl_sw5;
+    g6 = __builtin_parity(bb16);
+    return;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 70619e786d9..6910bb62c20 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -7213,6 +7213,16 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
       return false;
     }
 
+  /* We'll verify the reduction operation only later - avoid
+     all operations that mismatch on the number of SLP children.  */
+  if (op.num_ops != SLP_TREE_CHILDREN (slp_for_stmt_info).length ())
+    {
+      if (dump_enabled_p ())
+       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                        "unsupported reduction operation.\n");
+      return false;
+    }
+
   /* All uses but the last are expected to be defined in the loop.
      The last use is the reduction variable.  In case of nested cycle this
      assumption is not true: we use reduc_index to record the index of the
-- 
2.51.0

Reply via email to