From 515dba569d138d84e8a5f7ea71d38480732ee899 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Tue, 6 Jan 2026 14:10:38 +0100 Subject: [PATCH] tree-optimization/123316 - avoid ICE due to lack of PHI patterns 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. 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.47.3