https://gcc.gnu.org/g:b5ffe35f12e15e29b508eb937251d067febe18fe

commit r16-5644-gb5ffe35f12e15e29b508eb937251d067febe18fe
Author: Richard Biener <[email protected]>
Date:   Thu Nov 27 10:04:19 2025 +0100

    tree-optimization/122885 - avoid re-using accumulator for some bool vectors
    
    When boolean vectors do not use vector integer modes we are not
    set up to produce the partial epilog in a correctly typed way,
    so avoid this situation.  For the integer mode case we are able
    to pun things correctly, so keep that working.
    
            PR tree-optimization/122885
            * tree-vect-loop.cc (vect_find_reusable_accumulator): Reject
            mask vectors which do not use integer vector modes.
            (vect_create_partial_epilog): Assert the same.
    
            * gcc.dg/torture/pr122873.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/torture/pr122873.c | 13 +++++++++++++
 gcc/tree-vect-loop.cc                   |  9 +++++++++
 2 files changed, 22 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/torture/pr122873.c 
b/gcc/testsuite/gcc.dg/torture/pr122873.c
new file mode 100644
index 000000000000..1eadceedcd85
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr122873.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=armv9-a -msve-vector-bits=128" { target { 
aarch64-*-* } } } */
+/* { dg-additional-options "-mavx512bw -mavx512vl --param 
vect-partial-vector-usage=1" { target { avx512bw && avx512vl } } } */
+
+char *b;
+bool c(int l)
+{
+  bool d = true;
+  for (int a = 0; a < l; a++)
+    if (b[a])
+      d = false;
+  return d;
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index fe78107fe04c..ab6c0f084703 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -5026,6 +5026,12 @@ vect_find_reusable_accumulator (loop_vec_info loop_vinfo,
   if (VECT_REDUC_INFO_TYPE (reduc_info) != TREE_CODE_REDUCTION)
     return false;
 
+  /* We are not set up to handle vector bools when they are not mapped
+     to vector integer data types.  */
+  if (VECTOR_BOOLEAN_TYPE_P (vectype)
+      && GET_MODE_CLASS (TYPE_MODE (vectype)) != MODE_VECTOR_INT)
+    return false;
+
   unsigned int num_phis = VECT_REDUC_INFO_INITIAL_VALUES (reduc_info).length 
();
   auto_vec<tree, 16> main_loop_results (num_phis);
   auto_vec<tree, 16> initial_values (num_phis);
@@ -5126,6 +5132,9 @@ static tree
 vect_create_partial_epilog (tree vec_def, tree vectype, code_helper code,
                            gimple_seq *seq)
 {
+  gcc_assert (!VECTOR_BOOLEAN_TYPE_P (TREE_TYPE (vec_def))
+             || (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (vec_def)))
+                 == MODE_VECTOR_INT));
   unsigned nunits = TYPE_VECTOR_SUBPARTS (TREE_TYPE (vec_def)).to_constant ();
   unsigned nunits1 = TYPE_VECTOR_SUBPARTS (vectype).to_constant ();
   tree stype = TREE_TYPE (vectype);

Reply via email to