From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by sourceware.org (Postfix) with ESMTPS id C5BCB3858002 for ; Mon, 2 Nov 2020 09:49:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C5BCB3858002 Received: by mail-pg1-x52d.google.com with SMTP id h6so10326750pgk.4 for ; Mon, 02 Nov 2020 01:49:13 -0800 (PST) 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=d6/sTDtadB+osdcJUS+TZ1RnqXceKO06Ez/Iz4RjLJo=; b=KO426IDbIPaK36VA/fo7HGneWrkUhjhSqAO3lW62jJEc71cVN0RL42EpKqdTOGcM4y 01V+3TfChunaOBtHSEHp1dIcs1WF3waglmbV6mdb+qKrrTldSeZdcmca8e10H9PorYAa Ah1cQ2hsiHdz8z0tYcDm3PiJI+c2z768+CyfdFdpOYRBx6kaZYdxqDs7PQ8y0qPkfGGK LYOEQyOuI6mECogue+aIyIo6rCszbf9en6iTR5qk9Jla+Lr+SfbSbHMPP5wBSoCEzvO8 klJp6vJ1f5J9uiAlsrP6X9z6hgl9620VvdEhDoxtvjKsZCOMQkm500LI+3LIpmkszCVS CAog== X-Gm-Message-State: AOAM530v/ufMPU6/fW/zNIpE5VIrnJUheT93XCFvLff0M8wsQogqdmZh +VVRNdyCRBCvmyM4RBWE5JE= X-Google-Smtp-Source: ABdhPJx3XClD+BKZUpgUAAV4B3QdYEXEWGzqeqmJRs8cyvDsU0AUJvgZMhjyUvTOWDXroI4piLm6Rg== X-Received: by 2002:a17:90b:180d:: with SMTP id lw13mr7245061pjb.149.1604310553023; Mon, 02 Nov 2020 01:49:13 -0800 (PST) Received: from bubble.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id y124sm13256623pfy.28.2020.11.02.01.49.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Nov 2020 01:49:12 -0800 (PST) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 93BAC8587A; Mon, 2 Nov 2020 20:19:08 +1030 (ACDT) Date: Mon, 2 Nov 2020 20:19:08 +1030 From: Alan Modra To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, Segher Boessenkool Subject: [PATCH 2/2] [RS6000] REG_PARM_STACK_SPACE check V2 Message-ID: <20201102094908.GJ15956@bubble.grove.modra.org> References: <20201002071105.GP15011@bubble.grove.modra.org> <20201030134035.GF15956@bubble.grove.modra.org> <20201102094616.GI15956@bubble.grove.modra.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201102094616.GI15956@bubble.grove.modra.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, 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-List-Received-Date: Mon, 02 Nov 2020 09:49:15 -0000 On PowerPC we can tail call if the callee has less or equal REG_PARM_STACK_SPACE than the caller, as demonstrated by the testcase. So we should use /* If reg parm stack space increases, we cannot sibcall. */ if (REG_PARM_STACK_SPACE (decl ? decl : fntype) > INCOMING_REG_PARM_STACK_SPACE (current_function_decl)) and note the change to use INCOMING_REG_PARM_STACK_SPACE. REG_PARM_STACK_SPACE has always been wrong there for PowerPC. See https://gcc.gnu.org/pipermail/gcc-patches/2014-May/389867.html for why if you're curious. Not that it matters, because PowerPC can do without this check entirely, relying on a stack slot test in generic code. a) The generic code checks that arg passing stack in the callee is not greater than that in the caller, and, b) ELFv2 only allocates reg_parm_stack_space when some parameter is passed on the stack. Point (b) means that zero reg_parm_stack_space implies zero stack space, and non-zero reg_parm_stack_space implies non-zero stack space. So the case of 0 reg_parm_stack_space in the caller and 64 in the callee will be caught by (a). Bootstrapped and regression tested powerpc64le-linux and biarch powerpc64-linux. OK? PR middle-end/97267 gcc/ * config/rs6000/rs6000-logue.c (rs6000_function_ok_for_sibcall): Remove code checking REG_PARM_STACK_SPACE. testsuite/ * gcc.target/powerpc/pr97267.c: New test. diff --git a/gcc/config/rs6000/rs6000-logue.c b/gcc/config/rs6000/rs6000-logue.c index 61eb7ce7ade..d90cd5736e1 100644 --- a/gcc/config/rs6000/rs6000-logue.c +++ b/gcc/config/rs6000/rs6000-logue.c @@ -30,7 +30,6 @@ #include "df.h" #include "tm_p.h" #include "ira.h" -#include "calls.h" #include "print-tree.h" #include "varasm.h" #include "explow.h" @@ -1134,19 +1133,6 @@ rs6000_function_ok_for_sibcall (tree decl, tree exp) else fntype = TREE_TYPE (TREE_TYPE (CALL_EXPR_FN (exp))); - /* If outgoing reg parm stack space changes, we cannot do sibcall. */ - if ((OUTGOING_REG_PARM_STACK_SPACE (fntype) - != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl))) - || (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} } } */ -- Alan Modra Australia Development Lab, IBM