From patchwork Fri Oct 2 07:11:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 1375577 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=nSbtWNi1; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C2h4B4WBvz9s1t for ; Fri, 2 Oct 2020 17:11:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3EC74386F466; Fri, 2 Oct 2020 07:11:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3EC74386F466 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1601622675; bh=pAmO7vRmiU7iwM2FDfnnlX5aCj7CphF3+KfksdYDi38=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=nSbtWNi1LSynbb+Z4hFac847YlQQNT5163CrB4rg1W36GouwFCKm3/p4LgAt/tc+K 0vmrxndo/cimibPasu/0zKRvl9F5n7Rf5tSP5Hq2sGdWe70LZsOwd0MQJAMWSRcOA+ tzqZpKl1vcmsPpRr2C/8rvxXDe0Jrvlu6DYkX5Ek= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by sourceware.org (Postfix) with ESMTPS id A8396386EC66 for ; Fri, 2 Oct 2020 07:11:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A8396386EC66 Received: by mail-pj1-x1044.google.com with SMTP id i3so289082pjz.4 for ; Fri, 02 Oct 2020 00:11:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=pAmO7vRmiU7iwM2FDfnnlX5aCj7CphF3+KfksdYDi38=; b=ngmBPOoh5ksYP+XpJEFXioDN80yCkveTZTrxHuUFcGuVFChSTMVKuoFDGS5nQ6sKP8 eRX1mhCdyndbUhXzAfJHostOcd3MimHHZJ439Qzzo05FCk0aS6rqB6hfmLhTF7M+EV0T qq+Ei0kvEKFoIlTB+3DSyoaxjZUoSfGho2PQ/gKQ8Fr82BJYahE1vzZSmyeFIaF0sG28 cN6ezUOdCkTwilhKwgWNZV8uvaT7NOhzU3XaoKA9hfLjxcWK10d+GNMpQc63s2w2/2at 5aQ7fAsp2yDJEHMf5Vr08DzDluZyPiR2fQ0HqrKEpBb/QTZlEUpsYVdsO2CuHtGPrFRj FRwQ== X-Gm-Message-State: AOAM532dPaSKvZLo5UwuAtzNUsgOBL7733M7A+MDDGbLxGzR9AfxZWH2 mChs/ZfE5ZZxcfLo/B0z7PFvDMyyrxgr4w== X-Google-Smtp-Source: ABdhPJwMe/SGCA+eAbVI9qS8iIZS/+63lb2uRFmJVq/sNXyrWRMNyXsCHMMorNk4WajG7Dns6r2nsw== X-Received: by 2002:a17:90a:ae12:: with SMTP id t18mr1345704pjq.147.1601622670258; Fri, 02 Oct 2020 00:11:10 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:8592:62f7:fd74:1df0]) by smtp.gmail.com with ESMTPSA id h8sm774288pfk.19.2020.10.02.00.11.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 00:11:09 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id C079A85C86; Fri, 2 Oct 2020 16:41:05 +0930 (ACST) Date: Fri, 2 Oct 2020 16:41:05 +0930 To: gcc-patches@gcc.gnu.org Subject: [PATCH] calls.c:can_implement_as_sibling_call_p REG_PARM_STACK_SPACE check Message-ID: <20201002071105.GP15011@bubble.grove.modra.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Gcc-patches From: Alan Modra Reply-To: Alan Modra Cc: Segher Boessenkool Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This moves an #ifdef block of code from calls.c to targetm.function_ok_for_sibcall. Only two targets, x86 and rs6000, define REG_PARM_STACK_SPACE or OUTGOING_REG_PARM_STACK_SPACE macros that might vary depending on the called function. Macros like UNITS_PER_WORD don't change over a function boundary, nor does the MIPS ABI, nor does TARGET_64BIT on PA-RISC. Other targets are even more trivially seen to not need the calls.c code. Besides cleaning up a small piece of #ifdef code, the motivation for this patch is to allow tail calls on PowerPC for functions that require less reg_parm_stack_space than their caller. The original code in calls.c only permitted tail calls when exactly equal. Bootstrapped and regression tested powerpc64le-linux and x86_64-linux. OK for master? PR middle-end/97267 * calls.h (maybe_complain_about_tail_call): Declare. * calls.c (maybe_complain_about_tail_call): Make global. (can_implement_as_sibling_call_p): Move REG_PARM_STACK_SPACE check to.. * config/i386/i386.c (ix86_function_ok_for_sibcall): ..here, and.. * config/rs6000/rs6000-logue.c (rs6000_function_ok_for_sibcall): .. here. Modify to allow reg_parm_stack_space less or equal to caller, and delete redundant OUTGOING_REG_PARM_STACK_SPACE test. * testsuite/gcc.target/powerpc/pr97267.c: New test. diff --git a/gcc/calls.c b/gcc/calls.c index ed4363811c8..df7324f9343 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -1873,7 +1873,7 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp) /* Issue an error if CALL_EXPR was flagged as requiring tall-call optimization. */ -static void +void maybe_complain_about_tail_call (tree call_expr, const char *reason) { gcc_assert (TREE_CODE (call_expr) == CALL_EXPR); @@ -3501,20 +3501,6 @@ can_implement_as_sibling_call_p (tree exp, return false; } -#ifdef REG_PARM_STACK_SPACE - /* If outgoing reg parm stack space changes, we cannot do sibcall. */ - if (OUTGOING_REG_PARM_STACK_SPACE (funtype) - != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)) - || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl))) - { - maybe_complain_about_tail_call (exp, - "inconsistent size of stack space" - " allocated for arguments which are" - " passed in registers"); - return false; - } -#endif - /* Check whether the target is able to optimize the call into a sibcall. */ if (!targetm.function_ok_for_sibcall (fndecl, exp)) diff --git a/gcc/calls.h b/gcc/calls.h index dfb951ca45b..6d4feb59dd0 100644 --- a/gcc/calls.h +++ b/gcc/calls.h @@ -133,6 +133,7 @@ extern bool reference_callee_copied (CUMULATIVE_ARGS *, extern void maybe_warn_alloc_args_overflow (tree, tree, tree[2], int[2]); extern tree get_attr_nonstring_decl (tree, tree * = NULL); extern bool maybe_warn_nonstring_arg (tree, tree); +extern void maybe_complain_about_tail_call (tree, const char *); extern bool get_size_range (tree, tree[2], bool = false); extern rtx rtx_for_static_chain (const_tree, bool); extern bool cxx17_empty_base_field_p (const_tree); diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index f684954af81..58fc5280935 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -939,6 +939,19 @@ ix86_function_ok_for_sibcall (tree decl, tree exp) decl_or_type = type; } + /* If outgoing reg parm stack space changes, we cannot do sibcall. */ + if (OUTGOING_REG_PARM_STACK_SPACE (type) + != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)) + || (REG_PARM_STACK_SPACE (decl_or_type) + != REG_PARM_STACK_SPACE (current_function_decl))) + { + maybe_complain_about_tail_call (exp, + "inconsistent size of stack space" + " allocated for arguments which are" + " passed in registers"); + return false; + } + /* Check that the return value locations are the same. Like if we are returning floats on the 80387 register stack, we cannot make a sibcall from a function that doesn't return a float to a diff --git a/gcc/config/rs6000/rs6000-logue.c b/gcc/config/rs6000/rs6000-logue.c index d90cd5736e1..814b549e4ca 100644 --- a/gcc/config/rs6000/rs6000-logue.c +++ b/gcc/config/rs6000/rs6000-logue.c @@ -30,6 +30,7 @@ #include "df.h" #include "tm_p.h" #include "ira.h" +#include "calls.h" #include "print-tree.h" #include "varasm.h" #include "explow.h" @@ -1133,6 +1134,17 @@ rs6000_function_ok_for_sibcall (tree decl, tree exp) else fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); + /* If reg parm stack space increases, we cannot sibcall. */ + if (REG_PARM_STACK_SPACE (decl ? decl : fntype) + > REG_PARM_STACK_SPACE (current_function_decl)) + { + maybe_complain_about_tail_call (exp, + "inconsistent size of stack space" + " allocated for arguments which are" + " passed in registers"); + return false; + } + /* We can't do it if the called function has more vector parameters than the current function; there's nowhere to put the VRsave code. */ if (TARGET_ALTIVEC_ABI diff --git a/gcc/testsuite/gcc.target/powerpc/pr97267.c b/gcc/testsuite/gcc.target/powerpc/pr97267.c new file mode 100644 index 00000000000..cab46245fc9 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr97267.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +static int __attribute__ ((__noclone__, __noinline__)) +reg_args (int j1, int j2, int j3, int j4, int j5, int j6, int j7, int j8) +{ + return j1 + j2 + j3 + j4 + j5 + j6 + j7 + j8; +} + +int __attribute__ ((__noclone__, __noinline__)) +stack_args (int j1, int j2, int j3, int j4, int j5, int j6, int j7, int j8, + int j9) +{ + if (j9 == 0) + return 0; + return reg_args (j1, j2, j3, j4, j5, j6, j7, j8); +} + +/* { dg-final { scan-assembler-not {(?n)^\s+bl\s} } } */