https://gcc.gnu.org/g:5a76b4f528a654f0158aa6d9c43ef8bbf8d660f5
commit r16-7758-g5a76b4f528a654f0158aa6d9c43ef8bbf8d660f5 Author: Xi Ruoyao <[email protected]> Date: Fri Feb 27 16:54:40 2026 +0800 middle-end: allow expand_vector_broadcast to broadcast QImode to BImode vector [PR 124280] A boolean value is in QImode, but a vector of booleans is in VxxBImode. And both AArch64 SVE and RISC-V V have vec_duplicatevXXbi accepting a QI scalar. Allow this case. PR middle-end/124280 gcc/ * optabs.cc (expand_vector_broadcast): Allow broadcasting QImode to BImode vector. gcc/testsuite/ * gcc.c-torture/compile/pr124280.c: New test. Diff: --- gcc/optabs.cc | 7 +++++-- gcc/testsuite/gcc.c-torture/compile/pr124280.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gcc/optabs.cc b/gcc/optabs.cc index 249413c75763..111b9be99139 100644 --- a/gcc/optabs.cc +++ b/gcc/optabs.cc @@ -429,7 +429,8 @@ force_expand_binop (machine_mode mode, optab binoptab, } /* Create a new vector value in VMODE with all elements set to OP. If OP - is not a constant, the mode of it must be the element mode of VMODE. + is not a constant, the mode of it must be the element mode of VMODE + (if the element is BImode, additionally OP is allowed to be in QImode). If OP is a constant, then the return value will be a constant. */ rtx @@ -440,7 +441,9 @@ expand_vector_broadcast (machine_mode vmode, rtx op) gcc_checking_assert (VECTOR_MODE_P (vmode)); gcc_checking_assert (CONST_INT_P (op) - || GET_MODE_INNER (vmode) == GET_MODE (op)); + || GET_MODE_INNER (vmode) == GET_MODE (op) + || (GET_MODE_INNER (vmode) == BImode + && GET_MODE (op) == QImode)); if (valid_for_const_vector_p (vmode, op)) return gen_const_vec_duplicate (vmode, op); diff --git a/gcc/testsuite/gcc.c-torture/compile/pr124280.c b/gcc/testsuite/gcc.c-torture/compile/pr124280.c new file mode 100644 index 000000000000..86878f930187 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr124280.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-trapping-math -mcpu=neoverse-v2" { target aarch64-*-* } } */ + +void foo(int *__restrict a, int pblh, int *__restrict res, int n) +{ + int wts = a[0]; + for(int i = 0; i < n;i++) + { + if (a[i] < pblh && wts > 0) + res[i] = a[i]; + } +}
