From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 30A66385700F; Mon, 22 Mar 2021 11:05:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30A66385700F From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/28831] [8/9/10/11 Regression] Aggregate copy not elided when using a return value as a pass-by-value parameter Date: Mon, 22 Mar 2021 11:05:32 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 8.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 22 Mar 2021 11:05:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D28831 --- Comment #36 from Richard Biener --- Note that if we'd want to "preallocate" (or re-use) variables for argument slots we have to properly arrange them according to the ABI. Consider a function taking more than just a single argument [passed on stack] which we might still able to handle optimally [with greater difficulty]. Jasons C++ example expands from D.2368 =3D {}; D.2368.i[0] =3D 1; f (D.2368); if you modify that to struct A { int i[100]; }; void f(int i, struct A, int j); int main() { f(0, (struct A){1}, 2); } then on i?86 both extra arguments are passed on the stack as well but RTL expansion sees again D.2370 =3D {}; D.2370.i[0] =3D 1; f (0, D.2370, 2); but clearly we cannot just allocate D.2370 in a random place if it is passed on the stack (on i?86 it's passed by reference). For example struct A { int i[2]; }; void f(struct A); int main() { f((struct A){1}); } expanded as MEM [(struct A *)&D.1960 + 4B] =3D {}; D.1960.i[0] =3D 1; f (D.1960); is passed on the stack though. So if we want to expose anything on GIMPLE then we have to make the argument space on the stack distinct from random stack variables.=