From patchwork Tue Jan 9 01:03:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Wilson X-Patchwork-Id: 857187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-470490-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mUz729NY"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zFv6c41y6z9sP9 for ; Tue, 9 Jan 2018 12:04:06 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=ThVjtz3zN7b7EtOPq2RnaZw6zp/wcIsJ64RIhyKdefzUPcW8W2g3Y +6O8IlDI73czxWnUQjvw2g3+7wAO1WglRPMvJT6eVllDRS5c8rqun3Ui5iF01ppC AY4UItly5IdAibehZ5pgHV1PwGwsLrIDayuYfYwQ2h+yGA3gwaxPLY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:in-reply-to:references; s= default; bh=7t4p+hljtdeRMP9ZOR2Xn9MqnPU=; b=mUz729NYc6AUcPejg6s0 /JoKn7zvc9EwCCP6icKUiAfwIWMtkhNk85ASEA+CS61bUo8X7IAya7B0SnSoh9uw duQVIegW+d5DnoibcLLX1rEg5u5KVMqqIwytSAGjEdjzbR6YBkBxo05jm839f+qe 21KsmFqgAzD1W/v4gMZY1Yc= Received: (qmail 98738 invoked by alias); 9 Jan 2018 01:04:00 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 98712 invoked by uid 89); 9 Jan 2018 01:03:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-pg0-f67.google.com Received: from mail-pg0-f67.google.com (HELO mail-pg0-f67.google.com) (74.125.83.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 09 Jan 2018 01:03:57 +0000 Received: by mail-pg0-f67.google.com with SMTP id r2so6809168pgq.13 for ; Mon, 08 Jan 2018 17:03:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ekBYbj4Sw9ytVCstH1fwvk+/OL5MZnJutmdVMQBtyy4=; b=jED+UrzjA0Dj8xb5hp518W5MjwSZWwIdrt8Bn+7M+OHOvL9AwS/ULlJlJ6CwsZv8S2 M2cUzH+LJFoEUYFsKFh3/0p5LqMC5gRQF9/F8R/856POhUbOQZ/epoalqO/qVZSmYQa4 4hNtvusks3EU3T3qiJqglliQRJ3HeEMqpRYhxXz/45lIHJDGiuM6xrykmkVOpNBNGO2+ yjXZybIyF7t782qkp5vaqsMbvePmrEgP2S5+YID2KHsLSVoXoJiHOJ/eFWDYejZOXUwp jwT5IddS04rjJWwmm6x2mbHsaiJUVmV/Xx9XcmtaIWqsd2zSSKqKggnLn3gro5lVW5LI Oyww== X-Gm-Message-State: AKGB3mKBlG0gFhj/O+1rYR9Tfzkl9mqhapTgQimaBTZ/rKdbqucwuWbw 8uIyS6RqYq7atEGc6UlXacKVTcGec8M= X-Google-Smtp-Source: ACJfBovW1lSTNnwY0reGLOI/yJvyEKW9YqSBP6at/PlYQvDFv9K2GsqZwkZjARwrZcUBbbbabk6OUw== X-Received: by 10.98.70.19 with SMTP id t19mr5090558pfa.68.1515459835747; Mon, 08 Jan 2018 17:03:55 -0800 (PST) Received: from rohan.internal.sifive.com ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id r4sm4476822pfh.184.2018.01.08.17.03.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 17:03:55 -0800 (PST) From: Jim Wilson To: gcc-patches@gcc.gnu.org Cc: Jim Wilson Subject: [PATCH, gcc-7-branch] RISC-V: Fix -msave-restore bug with sibcalls. Date: Mon, 8 Jan 2018 17:03:39 -0800 Message-Id: <20180109010339.13866-1-jimw@sifive.com> In-Reply-To: <20180109004625.24689-1-jimw@sifive.com> References: <20180109004625.24689-1-jimw@sifive.com> The gcc-7-branch version of the patch. 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. 2017-11-29 Jim Wilson 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 (andrew@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 +# . + +# 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 + +__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(); +}