When XXTVarith extension is available, we can use a xt.vile/xt.vilo
instruction with a vrgather to perform the task of an even-odd
interleave. This approach can lead to better performance compared to
existing approaches that use vnsrl/vcompress + vslideup on XuanTie C950
series.
Regtested on rv64gcv and rv32gcv.
gcc/ChangeLog:
* config/riscv/riscv-v.cc (shuffle_even_odd_patterns): Use xt.vile
or xt.vilo with vrgather when XTheadVArith is available.
gcc/testsuite/ChangeLog:
*
gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith-run.c: New
test.
* gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith.c:
New test.
---
gcc/config/riscv/riscv-v.cc | 23 +++++++++++++++++++
.../vls-vlmax/shuffle-evenodd-xxtvarith-run.c | 7 ++++++
.../vls-vlmax/shuffle-evenodd-xxtvarith.c | 8 +++++++
3 files changed, 38 insertions(+)
create mode 100644
gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith-run.c
create mode 100644
gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith.c
diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 6ae806e01aa..c7d9adeecff 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -4046,6 +4046,29 @@ shuffle_even_odd_patterns (struct expand_vec_perm_d *d)
if (d->testing_p)
return true;
+ /* Use xt.vile/xt.vilo + vrgather when XXTVarith is available. */
+ if (TARGET_XXTVARITH)
+ {
+ rtx tmp = gen_reg_rtx (vmode);
+ insn_code vil_icode = even ? code_for_xt_pred (UNSPEC_XT_VILE, vmode)
+ : code_for_xt_pred (UNSPEC_XT_VILO, vmode);
+ rtx vil_ops[] = {tmp, d->op0, d->op1};
+ emit_vlmax_insn (vil_icode, (unsigned) __NORMAL_OP_TA2 | BINARY_OP_P,
+ vil_ops);
+
+ machine_mode sel_mode = related_int_vector_mode (vmode).require ();
+ machine_mode idx_mode = GET_MODE_INNER (sel_mode);
+ rvv_builder v (sel_mode, vlen, 1);
+ for (int i = 0; i < vlen / 2; i++)
+ v.quick_push (gen_int_mode (i * 2, idx_mode));
+ for (int i = 0; i < vlen / 2; i++)
+ v.quick_push (gen_int_mode (i * 2 + 1, idx_mode));
+ rtx idx = v.build ();
+
+ emit_vlmax_gather_insn (d->target, tmp, idx);
+ return true;
+ }
+
/* When the element width is smaller than the greatest ELEN, we can use two
vnsrl instructions, each extracting the even/odd elements of one source,
and a vslideup instruction to merge them into one vector.
diff --git
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith-run.c
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith-run.c
new file mode 100644
index 00000000000..1f648227307
--- /dev/null
+++
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith-run.c
@@ -0,0 +1,7 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_xxtvarith_ok } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-add-options riscv_v riscv_xxtvarith } */
+/* { dg-additional-options "-O3 -mrvv-max-lmul=m8 -std=gnu99" } */
+
+#include "shuffle-evenodd-run.c"
diff --git
a/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith.c
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith.c
new file mode 100644
index 00000000000..28dec853142
--- /dev/null
+++
b/gcc/testsuite/gcc.target/riscv/rvv/autovec/vls-vlmax/shuffle-evenodd-xxtvarith.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=rv64gcv_xxtvarith -mabi=lp64d -mrvv-max-lmul=m8" }
*/
+
+#include "shuffle-evenodd.c"
+
+/* { dg-final { scan-assembler-times "xt.vile" 24 } } */
+/* { dg-final { scan-assembler-times "xt.vilo" 24 } } */
+/* { dg-final { scan-assembler-times "vrgather" 48 } } */
--
2.47.1