Previously the spec
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/70
has changed the save/restore routines to save/restore the registers which
are really used for ILP32E/LP64 rather than always save/restore all
of ra/s0/s1.

I also found here that lacks the implementation for lp64e. If it's
necessary I will file anothor patch for that.

gcc/ChangeLog:

        * config/riscv/riscv.cc (riscv_compute_frame_info): Remove the
        dedicated calculation for RVE.

libgcc/ChangeLog:

        * config/riscv/save-restore.S: Only save/restore the registers
        which are really used for ILP32E/LP64.

gcc/testsuite/ChangeLog:

        * gcc.target/riscv/save-restore-cfi-3.c: New test.
---
 gcc/config/riscv/riscv.cc                     |  9 +---
 .../gcc.target/riscv/save-restore-cfi-3.c     | 16 ++++++
 libgcc/config/riscv/save-restore.S            | 50 ++++++++++++++++---
 3 files changed, 59 insertions(+), 16 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-cfi-3.c

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 985fe67f822..ef12198a523 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -8079,14 +8079,7 @@ riscv_compute_frame_info (void)
       /* Only use save/restore routines if they don't alter the stack size.  */
       if (riscv_stack_align (num_save_restore * UNITS_PER_WORD) == x_save_size
           && !riscv_avoid_save_libcall ())
-       {
-         /* Libcall saves/restores 3 registers at once, so we need to
-            allocate 12 bytes for callee-saved register.  */
-         if (TARGET_RVE)
-           x_save_size = 3 * UNITS_PER_WORD;
-
-         frame->save_libcall_adjustment = x_save_size;
-       }
+        frame->save_libcall_adjustment = x_save_size;
 
       if (!riscv_avoid_multi_push (frame))
        {
diff --git a/gcc/testsuite/gcc.target/riscv/save-restore-cfi-3.c 
b/gcc/testsuite/gcc.target/riscv/save-restore-cfi-3.c
new file mode 100644
index 00000000000..3d35ad185f7
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/save-restore-cfi-3.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-g -Os -march=rv32e -mabi=ilp32e -msave-restore" } */
+/* { dg-skip-if "" { *-*-* } {"-O2" "-O1" "-O0" "-Og" "-O3" "-Oz" "-flto"} } */
+/* { dg-final { scan-assembler-times {\.cfi_offset 8, -8} 1} } */
+/* { dg-final { scan-assembler-times {\.cfi_offset 1, -4} 1} } */
+/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 8} 1} } */
+/* { dg-final { scan-assembler-times {\.cfi_restore 8} 1} } */
+/* { dg-final { scan-assembler-times {\.cfi_restore 1} 1} } */
+/* { dg-final { scan-assembler-times {\.cfi_def_cfa_offset 0} 1} } */
+
+int my_getint();
+
+int foo(int x)
+{
+  return x + my_getint();
+}
diff --git a/libgcc/config/riscv/save-restore.S 
b/libgcc/config/riscv/save-restore.S
index fc654472a4c..f6519e35e37 100644
--- a/libgcc/config/riscv/save-restore.S
+++ b/libgcc/config/riscv/save-restore.S
@@ -298,9 +298,8 @@ FUNC_END (__riscv_restore_0)
 #else
 
 #ifdef __riscv_abi_rve
+
 FUNC_BEGIN(__riscv_save_2)
-FUNC_BEGIN(__riscv_save_1)
-FUNC_BEGIN(__riscv_save_0)
   .cfi_startproc
   # __riscv_save_* routine use t0/x5 as return address
   .cfi_return_column 5
@@ -316,21 +315,56 @@ FUNC_BEGIN(__riscv_save_0)
   jr t0
   .cfi_endproc
 FUNC_END(__riscv_save_2)
+
+FUNC_BEGIN(__riscv_save_1)
+  .cfi_startproc
+  # __riscv_save_* routine use t0/x5 as return address
+  .cfi_return_column 5
+  addi sp, sp, -8
+  .cfi_def_cfa_offset 8
+  sw s0, 0(sp)
+  .cfi_offset 8, -8
+  sw ra, 4(sp)
+  .cfi_offset 1, -4
+  SET_LPAD
+  jr t0
+  .cfi_endproc
 FUNC_END(__riscv_save_1)
+
+FUNC_BEGIN(__riscv_save_0)
+  .cfi_startproc
+  # __riscv_save_* routine use t0/x5 as return address
+  .cfi_return_column 5
+  addi sp, sp, -4
+  .cfi_def_cfa_offset 4
+  sw ra, 0(sp)
+  .cfi_offset 1, -4
+  SET_LPAD
+  jr t0
+  .cfi_endproc
 FUNC_END(__riscv_save_0)
 
 FUNC_BEGIN(__riscv_restore_2)
-FUNC_BEGIN(__riscv_restore_1)
-FUNC_BEGIN(__riscv_restore_0)
   .cfi_startproc
-  .cfi_def_cfa_offset 14
+  .cfi_def_cfa_offset 12
   lw s1, 0(sp)
   .cfi_restore 9
-  lw s0, 4(sp)
+  addi sp, sp, 4
+
+FUNC_BEGIN(__riscv_restore_1)
+  .cfi_restore 9
+  .cfi_def_cfa_offset 8
+  lw s0, 0(sp)
   .cfi_restore 8
-  lw ra, 8(sp)
+  addi sp, sp, 4
+
+FUNC_BEGIN(__riscv_restore_0)
+  .cfi_restore 8
+  .cfi_restore 9
+  .cfi_def_cfa_offset 4
+  lw ra, 0(sp)
   .cfi_restore 1
-  addi sp, sp, 12
+  addi sp, sp, 4
   .cfi_def_cfa_offset 0
   ret
   .cfi_endproc
-- 
2.43.5

Reply via email to