From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id A17DC3857C4E for ; Mon, 15 Feb 2021 22:44:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A17DC3857C4E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=segher@kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 11FMhAxY031438; Mon, 15 Feb 2021 16:43:11 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 11FMhAKH031435; Mon, 15 Feb 2021 16:43:10 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 15 Feb 2021 16:43:10 -0600 From: Segher Boessenkool To: Stefan Ring Cc: gcc-help Subject: Re: Interesting regression in parameter passing (x86_64) Message-ID: <20210215224310.GK28121@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, KAM_SHORT, SCC_5_SHORT_WORD_LINES, TXREP, T_SPF_HELO_PERMERROR, T_SPF_PERMERROR autolearn=no 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-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Feb 2021 22:44:13 -0000 Hi! On Sun, Feb 14, 2021 at 12:38:26PM +0100, Stefan Ring via Gcc-help wrote: > I recently noticed that gcc 9 introduced a strange push/pop pair in a > function that does nothing other than shift all arguments by one > position and transfer control to another function: > > int func(int, int, int, int, int, int); > int caller(int a, int b, int c, int d, int e) { return func(0, a, b, c, d, e); } > > pushq %r12 > movl %r8d, %r9d > popq %r12 > movl %ecx, %r8d > movl %edx, %ecx > movl %esi, %edx > movl %edi, %esi > xorl %edi, %edi > jmp func > > Obviously, pushing and popping r12 serves no useful purpose, and gcc 8 > does not produce it. It also disappears when a is used instead of the > constant 0 as the first argument. Where does this come from? The pop was emitted right before the jump, but it was moved to earlier by the instruction scheduled (sched2). The prologue/epilogue push and pop r12 because that is a non-volatile ("callee-saved") register. At the point the prologue and expilogue code is generated r12 is used in the code, to shuffle these registers through. It is essentially r10 := edi r11 := esi r12 := edx r9 := r8 r8 := ecx ecx := r12 edx := r11 esi := r10 edi := 0 which then by cprop_hardreg is simplified to r9 := r8 r8 := ecx ecx := edx edx := esi esi := edi edi := 0 but by then it is too late to omit the push and pop. Please open a PR (see https://gcc.gnu.org/bugs.html for how). Thanks! Segher