]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/123316 - avoid ICE due to lack of PHI patterns
authorRichard Biener <rguenther@suse.de>
Tue, 6 Jan 2026 13:10:38 +0000 (14:10 +0100)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 7 Jan 2026 08:18:28 +0000 (09:18 +0100)
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 [new file with mode: 0644]
gcc/tree-vect-loop.cc

diff --git a/gcc/testsuite/gcc.dg/vect/vect-pr123316.c b/gcc/testsuite/gcc.dg/vect/vect-pr123316.c
new file mode 100644 (file)
index 0000000..dc3284a
--- /dev/null
@@ -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;
+}
index 8e60a433596f64bbc67119631fa3e01fe14884e4..a82949745e8474d07e8e8e4dc4320495fcc148d4 100644 (file)
@@ -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;