From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A391F385800A; Sat, 1 May 2021 19:20:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A391F385800A From: "luc.vanoostenryck at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/100377] New: needless stack adjustment when passing struct in register Date: Sat, 01 May 2021 19:20:51 +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: luc.vanoostenryck at gmail 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 attachments.created 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: Sat, 01 May 2021 19:20:51 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100377 Bug ID: 100377 Summary: needless stack adjustment when passing struct in register Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: luc.vanoostenryck at gmail dot com Target Milestone: --- Created attachment 50726 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D50726&action=3Dedit testcases When compiling with optimization for example -O2), the following code: struct sb { signed char a; char b; short y[3]; }; struct ub { unsigned char a; char b; short y[3]; }; int fsb(struct sb s) { return s.a; } int fub(struct ub s) { return s.a; } produces the following assembly code on arm64: fsb: sub sp, sp, #16 sxtb w0, w0 add sp, sp, 16 ret fub: sub sp, sp, #16 and w0, w0, 255 add sp, sp, 16 ret the following on mips64: fsb: daddiu $sp,$sp,-16 dsll $2,$4,56 dsra $2,$2,56 j $31 daddiu $sp,$sp,16 fub: daddiu $sp,$sp,-16 andi $2,$4,0xff j $31 daddiu $sp,$sp,16 the following on riscv64: fsb: addi sp,sp,-16 slli a0,a0,24 srai a0,a0,24 addi sp,sp,16 jr ra fub: addi sp,sp,-16 andi a0,a0,0xff addi sp,sp,16 jr ra OTOH, things seems OK on ppc64: fsb: extsb 3,3 blr fub: rlwinm 3,3,0,0xff blr and x86_64: fsb: movsx eax, dil ret fub: movzx eax, dil ret Similar problems happen on 32-bit platforms too. For example on arm32, the following code: struct ub32 { unsigned char a; char b; short y[1]; }; int fub32(struct ub32 s) { return s.a; } produces: fub32: sub sp, sp, #8 uxtb r0, r0 add sp, sp, #8 bx lr All these seem to happen on all versions. See https://gcc.godbolt.org/z/x9zc1EnYn Note: similar PRs exist but reported for x86_64 only=