public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: testsuite: ensure vtype is call clobbered
@ 2024-03-27 22:14 Vineet Gupta
  2024-03-28 13:41 ` Jeff Law
  0 siblings, 1 reply; 3+ messages in thread
From: Vineet Gupta @ 2024-03-27 22:14 UTC (permalink / raw)
  To: gcc-patches
  Cc: Jeff Law, kito.cheng, Palmer Dabbelt, gnu-toolchain, charlie,
	Vineet Gupta

Per classic Vector calling convention ABI, vtype is call clobbered,
so ensure gcc generates fresh a VSETVLI after a function call or an
inline asm which clobbers vtype.

ATM gcc seems to be doing the right thing, but a test can never be
harmful.

gcc/testsuite/ChangeLog:
	* gcc.target/riscv/rvv/vtype-call-clobbered.c: New Test.

Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
---
 .../riscv/rvv/vtype-call-clobbered.c          | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vtype-call-clobbered.c

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 000000000000..be9f312aa508
--- /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 } } */
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: testsuite: ensure vtype is call clobbered
  2024-03-27 22:14 [PATCH] RISC-V: testsuite: ensure vtype is call clobbered Vineet Gupta
@ 2024-03-28 13:41 ` Jeff Law
  2024-03-28 17:27   ` [COMMITTED] " Vineet Gupta
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Law @ 2024-03-28 13:41 UTC (permalink / raw)
  To: Vineet Gupta, gcc-patches
  Cc: kito.cheng, Palmer Dabbelt, gnu-toolchain, charlie



On 3/27/24 4:14 PM, Vineet Gupta wrote:
> Per classic Vector calling convention ABI, vtype is call clobbered,
> so ensure gcc generates fresh a VSETVLI after a function call or an
> inline asm which clobbers vtype.
> 
> ATM gcc seems to be doing the right thing, but a test can never be
> harmful.
> 
> gcc/testsuite/ChangeLog:
> 	* gcc.target/riscv/rvv/vtype-call-clobbered.c: New Test.
OK
jeff


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [COMMITTED] RISC-V: testsuite: ensure vtype is call clobbered
  2024-03-28 13:41 ` Jeff Law
@ 2024-03-28 17:27   ` Vineet Gupta
  0 siblings, 0 replies; 3+ messages in thread
From: Vineet Gupta @ 2024-03-28 17:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Vineet Gupta

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>
---
 .../riscv/rvv/vtype-call-clobbered.c          | 47 +++++++++++++++++++
 1 file changed, 47 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/vtype-call-clobbered.c

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 000000000000..be9f312aa508
--- /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 } } */
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-28 17:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27 22:14 [PATCH] RISC-V: testsuite: ensure vtype is call clobbered Vineet Gupta
2024-03-28 13:41 ` Jeff Law
2024-03-28 17:27   ` [COMMITTED] " Vineet Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).