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>
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
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-ffat-lto-objects" } */
+
+void foo() {
+ asm volatile("# " : ::"ra");
+}
+
+/* { dg-final { scan-assembler "s(w|d)\[ \t\]*ra" } } */