From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by sourceware.org (Postfix) with ESMTPS id 49797385040C for ; Sun, 4 Oct 2020 12:39:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 49797385040C Received: by mail-pj1-x1042.google.com with SMTP id a17so3136578pju.1 for ; Sun, 04 Oct 2020 05:39:17 -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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=xVap/EX+jhPICTP0Lr7DUny8TijhAGkGWk+ZSyyNQas=; b=Re4X1G6ApyEaS2W+7FeTOqyEv6nPOrSHu8IP+07F9zTZ+7f1fIF8vNQo03LBADF8oR UEe+3Ke+MjUqRvSM9hCyM2Ua5Imkws5i9TG7nknJ6hkOrP8MwZVvhUpmoBPjqXflkAzy FmgZTN8coljmFNtN7RIJCW3Uss48W1CepDMyKttf0xHlJsecXHPj4h8iXJNo9VCbtw5s AE+0eUp6J0PRUQsgdQxG4ePlgwKlXEcZ5CDOp/8BB1ZcOjGs3uN+g73LA0hquoTvoQOb j2aGouyDWsJ5TaU9Kj9LZx2qIrE4pUTtZ9mSvaA6Ve1k/TQ57FG59F678JHfgI9St2Rb ACsQ== X-Gm-Message-State: AOAM531dBBPLkCmVjLZAt3qrxMbkBuks13h+L+omA8YH/fvJnWLJm9GE Bs1maVg5gbymGVNUkX+bKAoU5Tl+i/S1Cw== X-Google-Smtp-Source: ABdhPJy8QLa1BP9WlVGTci9mD3KZN71WKZd0T5g7A7h7apt9sKsrA/8kNuEm0mj0qsCr11eocqLk8A== X-Received: by 2002:a17:90b:80a:: with SMTP id bk10mr11643236pjb.53.1601815155933; Sun, 04 Oct 2020 05:39:15 -0700 (PDT) Received: from bubble.grove.modra.org ([2406:3400:51d:8cc0:e4b9:4404:3672:a509]) by smtp.gmail.com with ESMTPSA id 31sm7402080pgs.59.2020.10.04.05.39.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Oct 2020 05:39:14 -0700 (PDT) Received: by bubble.grove.modra.org (Postfix, from userid 1000) id 22C3F859F6; Sun, 4 Oct 2020 23:09:11 +1030 (ACDT) Date: Sun, 4 Oct 2020 23:09:11 +1030 From: Alan Modra To: Segher Boessenkool Cc: gcc-patches@gcc.gnu.org, Jeff Law Subject: Re: [PATCH] calls.c:can_implement_as_sibling_call_p REG_PARM_STACK_SPACE check Message-ID: <20201004123910.GT15011@bubble.grove.modra.org> References: <20201002071105.GP15011@bubble.grove.modra.org> <20201002185024.GX28786@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201002185024.GX28786@gate.crashing.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: Sun, 04 Oct 2020 12:39:18 -0000 Hi Segher, On Fri, Oct 02, 2020 at 01:50:24PM -0500, Segher Boessenkool wrote: > On Fri, Oct 02, 2020 at 04:41:05PM +0930, Alan Modra wrote: > > 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. > > > + /* 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; > > + } > > Maybe change the message? You allow all sizes smaller or equal than > the current size, "inconsistent" isn't very great for that. We're talking about just two sizes here. For 64-bit ELFv2 the reg parm save size is either 0 or 64 bytes. Yes, a better message would be "caller lacks stack space allocated for aguments passed in registers, required by callee". Note that I'll likely be submitting a further patch that removes the above code in rs6000-logue.c. I thought is safer to only make a small change at the same time as moving code around. The reasoning behind a followup patch is: a) The generic code checks that arg passing space in the called function is not greater than that in the current function, 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 arg space, and non-zero reg_parm_stack_space implies non-zero stack arg space. So the case of 0 reg_parm_stack_space in the caller and 64 in the callee will be caught by (a). Also, there's a bug in the code I moved from calls.c. It should be using INCOMING_REG_PARM_STACK_SPACE, to properly compare space known to be allocated for the current function vs. space needed for the called function. For an explanation of INCOMING_REG_PARM_STACK_SPACE see https://gcc.gnu.org/pipermail/gcc-patches/2014-May/389867.html Of course that bug doesn't matter in this context because it's always been covered up by (a). -- Alan Modra Australia Development Lab, IBM