From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3C3E63858D37; Thu, 3 Feb 2022 19:20:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C3E63858D37 From: "palchak at google dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/104372] New: [ARM] Unnecessary writes to stack when passing aggregate in registers Date: Thu, 03 Feb 2022 19:20:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: palchak at google dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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: Thu, 03 Feb 2022 19:20:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104372 Bug ID: 104372 Summary: [ARM] Unnecessary writes to stack when passing aggregate in registers Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: palchak at google dot com Target Milestone: --- Missed optimization when an aggregate is passed by value entirely in regist= ers: struct Bar {}; struct Foo { Bar *addr; int size; }; Bar* MakeBar1(Bar *addr, int) noexcept { return addr; } Bar* MakeBar2(Foo foo) noexcept { return foo.addr; } When compiled with '-O2' using 'arm-unknown-linux-gnueabihf-g++ (GCC) 12.0.= 0' generates: MakeBar1(Bar*, int): bx lr MakeBar2(Foo): sub sp, sp, #8 add r3, sp, #8 stmdb r3, {r0, r1} add sp, sp, #8 bx lr The creation of a stack frame in MakeBar2 is completely unnecessary. For comparison, Clang 11.0.1 generates identical code for both functions that matches MakeBar1 shown here.=