public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] RISC-V: Save/restore ra register correctly [PR112478]
@ 2023-11-21  4:09 Jeff Law
  0 siblings, 0 replies; only message in thread
From: Jeff Law @ 2023-11-21  4:09 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:0963234ccc5b3ee4bc63cc6923eb5daae52d57b1

commit 0963234ccc5b3ee4bc63cc6923eb5daae52d57b1
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Tue Nov 14 11:17:45 2023 +0800

    RISC-V: Save/restore ra register correctly [PR112478]
    
    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>
    (cherry picked from commit defa8681d951c6d6c43c71e3636ce4db9de04a28)

Diff:
---
 gcc/config/riscv/riscv.cc                 | 4 ++++
 gcc/testsuite/gcc.target/riscv/pr112478.c | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 6a13c4b68b5..2073fe7803c 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -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
index 00000000000..0bbde20b71b
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/pr112478.c
@@ -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" } } */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-21  4:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21  4:09 [gcc(refs/vendors/riscv/heads/gcc-13-with-riscv-opts)] RISC-V: Save/restore ra register correctly [PR112478] Jeff Law

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).