From b5ffe35f12e15e29b508eb937251d067febe18fe Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 27 Nov 2025 10:04:19 +0100 Subject: [PATCH] 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. --- gcc/testsuite/gcc.dg/torture/pr122873.c | 13 +++++++++++++ gcc/tree-vect-loop.cc | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr122873.c diff --git a/gcc/testsuite/gcc.dg/torture/pr122873.c b/gcc/testsuite/gcc.dg/torture/pr122873.c new file mode 100644 index 00000000000..1eadceedcd8 --- /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 fe78107fe04..ab6c0f08470 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 main_loop_results (num_phis); auto_vec 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); -- 2.47.3