With bools we can end up with mixed vector types in PHI nodes due
to PHIs not having pattern stmts. Avoid this when analyzing
a nested cycle, similar to how we already to when analyzing BB
vectorization PHIs.
Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
PR tree-optimization/123316
* tree-vect-loop.cc (vectorizable_reduction): Detect missing
PHI patterns for bools.
* gcc.dg/vect/vect-pr123316.c: New testcase.
---
gcc/testsuite/gcc.dg/vect/vect-pr123316.c | 10 ++++++++++
gcc/tree-vect-loop.cc | 15 +++++++++++++++
2 files changed, 25 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/vect/vect-pr123316.c
diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr123316.c
b/gcc/testsuite/gcc.dg/vect/vect-pr123316.c
new file mode 100644
index 00000000000..dc3284ae7de
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/vect-pr123316.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+int a;
+extern bool b[];
+void e (int c)
+{
+ for (; c; c++)
+ for (int d = 2; d < 21; d++)
+ b[c] |= a;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 8e60a433596..a82949745e8 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -6979,6 +6979,21 @@ vectorizable_reduction (loop_vec_info loop_vinfo,
"invariants\n");
return false;
}
+ else if (SLP_TREE_DEF_TYPE (child) == vect_internal_def
+ && !useless_type_conversion_p (SLP_TREE_VECTYPE (slp_node),
+ SLP_TREE_VECTYPE (child)))
+ {
+ /* With bools we can have mask and non-mask precision vectors
+ or different non-mask precisions. while pattern recog is
+ supposed to guarantee consistency here, we do not have
+ pattern stmts for PHIs (PR123316).
+ Deal with that here instead of ICEing later. */
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+ "incompatible vector type setup from "
+ "bool pattern detection\n");
+ return false;
+ }
/* Analysis for double-reduction is done on the outer
loop PHI, nested cycles have no further restrictions. */
SLP_TREE_TYPE (slp_node) = cycle_phi_info_type;
--
2.51.0