]> gcc.gnu.org Git - gcc.git/commitdiff
RISC-V: Save/restore ra register correctly [PR112478]
authorKito Cheng <kito.cheng@sifive.com>
Tue, 14 Nov 2023 03:17:45 +0000 (11:17 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Thu, 16 Nov 2023 11:36:23 +0000 (19:36 +0800)
We set ra to fixed register now, but we still need to save/restore that at
prologue/epilogue if that has used.

gcc/ChangeLog:

PR target/112478
* config/riscv/riscv.cc (riscv_save_return_addr_reg_p): Check ra
is ever lived.

gcc/testsuite/ChangeLog:

PR target/112478
* gcc.target/riscv/pr112478.c: New.

Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu>
Tested-by: Christoph Müllner <christoph.muellner@vrull.eu>
gcc/config/riscv/riscv.cc
gcc/testsuite/gcc.target/riscv/pr112478.c [new file with mode: 0644]

index e466d4f168aff1fe24f8390a74ddc1dc7c9cb549..aada6ac76c8b827f763337f97cc65f8ef5dfcaf0 100644 (file)
@@ -5825,6 +5825,10 @@ riscv_save_return_addr_reg_p (void)
   if (riscv_far_jump_used_p ())
     return true;
 
+  /* We need to save it if anyone has used that.  */
+  if (df_regs_ever_live_p (RETURN_ADDR_REGNUM))
+    return true;
+
   /* Need not to use ra for leaf when frame pointer is turned off by
      option whatever the omit-leaf-frame's value.  */
   if (frame_pointer_needed && crtl->is_leaf
diff --git a/gcc/testsuite/gcc.target/riscv/pr112478.c b/gcc/testsuite/gcc.target/riscv/pr112478.c
new file mode 100644 (file)
index 0000000..0bbde20
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-ffat-lto-objects" } */
+
+void foo() {
+    asm volatile("# " : ::"ra");
+}
+
+/* { dg-final { scan-assembler "s(w|d)\[ \t\]*ra" } } */
This page took 0.090111 seconds and 5 git commands to generate.