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.
---
Tested with RUNTESTFLAGS=compile.exp=pr124280.c with an
aarch64-linux-gnu cross compiler. Ok for trunk?
gcc/optabs.cc | 7 +++++--
gcc/testsuite/gcc.c-torture/compile/pr124280.c | 12 ++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr124280.c
diff --git a/gcc/optabs.cc b/gcc/optabs.cc
index 249413c7576..111b9be9913 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 00000000000..86878f93018
--- /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];
+ }
+}
--
2.53.0