aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVineet Gupta <vineetg@rivosinc.com>2024-03-27 14:55:04 -0700
committerVineet Gupta <vineetg@rivosinc.com>2024-03-28 10:25:39 -0700
commitc1424628dc95829408882f01cbf0dd61566dc312 (patch)
treea927670271748e4d1955698350eae132a918d9f2
parentaeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3 (diff)
downloadgcc-c1424628dc95829408882f01cbf0dd61566dc312.zip
gcc-c1424628dc95829408882f01cbf0dd61566dc312.tar.gz
gcc-c1424628dc95829408882f01cbf0dd61566dc312.tar.bz2
RISC-V: testsuite: ensure vtype is call clobbered
Per classic Vector calling convention ABI, vtype is call clobbered, so ensure gcc regenerates a VSETVLI in following cases: - after a function call. - after an inline asm fragment which clobbers vtype. ATM gcc seems to be doing the right thing, but a test can never hurt. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/vtype-call-clobbered.c: New Test. Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
-rw-r--r--gcc/testsuite/gcc.target/riscv/rvv/vtype-call-clobbered.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/vtype-call-clobbered.c b/gcc/testsuite/gcc.target/riscv/rvv/vtype-call-clobbered.c
new file mode 100644
index 0000000..be9f312
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/vtype-call-clobbered.c
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gcv -mabi=lp64 -O2" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
+
+#include "riscv_vector.h"
+
+extern void can_clobber_vtype();
+
+static inline void v_loop (void * restrict in, void * restrict out, int n)
+{
+ for (int i = 0; i < n; i++)
+ {
+ vuint8mf8_t v = *(vuint8mf8_t*)(in + i);
+ *(vuint8mf8_t*)(out + i) = v;
+ }
+}
+
+/* Two V instructions back-back.
+ Only 1 vsetvli insn. */
+void
+vec1 (void * restrict in, void * restrict out1, void * restrict out2, int n)
+{
+ v_loop(in, out1, n);
+ v_loop(in, out2, n);
+}
+
+/* Two V instructions seperated by a function call.
+ Both need to have a corresponding vsetvli insn. */
+void
+vec2 (void * restrict in, void * restrict out1, void * restrict out2, int n)
+{
+ v_loop(in, out1, n);
+ can_clobber_vtype();
+ v_loop(in, out2, n);
+}
+
+/* Two V instructions seperated by an inline asm with vtype clobber.
+ Both need to have a corresponding vsetvli insn. */
+void
+vec3 (void * restrict in, void * restrict out1, void * restrict out2, int n)
+{
+ v_loop(in, out1, n);
+ asm volatile("":::"vtype");
+ v_loop(in, out2, n);
+}
+
+/* { dg-final { scan-assembler-times {vsetvli} 5 } } */