The following avoids ICEing with a reduction only consisting of
noop-conversions.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
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.
---
gcc/testsuite/gcc.dg/vect/vect-pr123221.c | 14 ++++++++++++++
gcc/tree-vect-loop.cc | 7 +++++++
2 files changed, 21 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-pr123221.c
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 00000000000..642517926d0
--- /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 a82949745e8..994d1a3ee74 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. */
--
2.51.0