The gcc-7-branch version of the patch.

       2018-01-08  Monk Chiang  <sh.chian...@gmail.com>
                    Kito Cheng  <kito.ch...@gmail.com>
        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 <pkmx...@gmail.com>
                    Monk Chiang  <sh.chian...@gmail.com>
        gcc/testsuite/
        * gcc.target/riscv/save-restore-1.c: New.

        2017-11-29  Jim Wilson  <j...@sifive.com>
        gcc/testsuite/
        * gcc.target/riscv/riscv.exp: New.
---
 gcc/config/riscv/riscv.c                        | 20 ++----------
 gcc/testsuite/gcc.target/riscv/riscv.exp        | 41 +++++++++++++++++++++++++
 gcc/testsuite/gcc.target/riscv/save-restore-1.c | 25 +++++++++++++++
 3 files changed, 69 insertions(+), 17 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/riscv/riscv.exp
 create mode 100644 gcc/testsuite/gcc.target/riscv/save-restore-1.c

diff --git a/gcc/config/riscv/riscv.c b/gcc/config/riscv/riscv.c
index 73312712d33..5f53819eb36 100644
--- a/gcc/config/riscv/riscv.c
+++ b/gcc/config/riscv/riscv.c
@@ -1,5 +1,5 @@
 /* Subroutines used for code generation for RISC-V.
-   Copyright (C) 2011-2017 Free Software Foundation, Inc.
+   Copyright (C) 2011-2018 Free Software Foundation, Inc.
    Contributed by Andrew Waterman (and...@sifive.com).
    Based on MIPS target for GNU compiler.
 
@@ -177,9 +177,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;
 };
@@ -3994,26 +3991,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/gcc.target/riscv/riscv.exp 
b/gcc/testsuite/gcc.target/riscv/riscv.exp
new file mode 100644
index 00000000000..6a141964d22
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/riscv.exp
@@ -0,0 +1,41 @@
+# Copyright (C) 2017-2018 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# GCC testsuite that uses the `dg.exp' driver.
+
+# Exit immediately if this isn't a RISC-V target.
+if ![istarget riscv*-*-*] then {
+  return
+}
+
+# Load support procs.
+load_lib gcc-dg.exp
+
+# If a testcase doesn't have special options, use these.
+global DEFAULT_CFLAGS
+if ![info exists DEFAULT_CFLAGS] then {
+    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
+}
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
+       "" $DEFAULT_CFLAGS
+
+# All done.
+dg-finish
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 <stdlib.h>
+
+__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();
+}
-- 
2.14.1

Reply via email to