From: Jim Wilson Date: Tue, 9 Jan 2018 00:45:46 +0000 (-0800) Subject: RISC-V: Fix -msave-restore bug with sibcalls. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c8a0c7b660a96081f320c8155f135a46b2202968;p=gcc.git RISC-V: Fix -msave-restore bug with sibcalls. 2018-01-08 Monk Chiang Kito Cheng gcc/ * config/riscv/riscv.c (machine_function::is_leaf): Remove field. (riscv_leaf_function_p): Delete. (riscv_function_ok_for_sibcall): Return false when TARGET_SAVE_RESTORE. 2018-01-08 Chih-Mao Chen Monk Chiang gcc/testsuite/ * gcc.target/riscv/save-restore-1.c: New. From-SVN: r256362 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 292d62de4f4..d8e84c57aac 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-01-08 Monk Chiang + Kito Cheng + + * config/riscv/riscv.c (machine_function::is_leaf): Remove field. + (riscv_leaf_function_p): Delete. + (riscv_function_ok_for_sibcall): Return false when TARGET_SAVE_RESTORE. + 2018-01-08 Bill Schmidt PR target/83677 diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c index 39e12507e68..b6270f7bfd7 100644 --- a/gcc/config/riscv/riscv.c +++ b/gcc/config/riscv/riscv.c @@ -127,9 +127,6 @@ struct GTY(()) machine_function { This area is allocated by the callee at the very top of the frame. */ int varargs_size; - /* Memoized return value of leaf_function_p. <0 if false, >0 if true. */ - int is_leaf; - /* The current frame information, calculated by riscv_compute_frame_info. */ struct riscv_frame_info frame; }; @@ -4176,26 +4173,15 @@ riscv_trampoline_init (rtx m_tramp, tree fndecl, rtx chain_value) emit_insn (gen_clear_cache (addr, end_addr)); } -/* Return leaf_function_p () and memoize the result. */ - -static bool -riscv_leaf_function_p (void) -{ - if (cfun->machine->is_leaf == 0) - cfun->machine->is_leaf = leaf_function_p () ? 1 : -1; - - return cfun->machine->is_leaf > 0; -} - /* Implement TARGET_FUNCTION_OK_FOR_SIBCALL. */ static bool riscv_function_ok_for_sibcall (tree decl ATTRIBUTE_UNUSED, tree exp ATTRIBUTE_UNUSED) { - /* When optimzing for size, don't use sibcalls in non-leaf routines */ + /* Don't use sibcalls when use save-restore routine. */ if (TARGET_SAVE_RESTORE) - return riscv_leaf_function_p (); + return false; return true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 847f1b937b1..9b0f827349f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-01-08 Chih-Mao Chen + Monk Chiang + + * gcc.target/riscv/save-restore-1.c: New. + 2018-01-08 Bill Schmidt PR target/83677 diff --git a/gcc/testsuite/gcc.target/riscv/save-restore-1.c b/gcc/testsuite/gcc.target/riscv/save-restore-1.c new file mode 100644 index 00000000000..35b08b96760 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/save-restore-1.c @@ -0,0 +1,25 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -msave-restore -fomit-frame-pointer" } */ + +#include + +__attribute__((noinline)) int g(void) { return 42; } + +__attribute__((noinline)) int f(void) { + asm volatile ("li s0, 0x87654321" ::: "s0"); + return g(); +} + +int main(void) { + asm volatile ("li s0, 0x12345678" ::: "s0"); + + f(); + + long s0; + asm volatile ("mv %0, s0" : "=r"(s0)); + + if (s0 == 0x12345678) + exit (0); + else + abort(); +}