public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "luc.vanoostenryck at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-100377-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100377 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=50726&action=edit 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
next reply other threads:[~2021-05-01 19:20 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-05-01 19:20 luc.vanoostenryck at gmail dot com [this message] 2021-05-01 20:59 ` [Bug rtl-optimization/100377] " pinskia at gcc dot gnu.org 2021-05-01 21:00 ` pinskia at gcc dot gnu.org 2021-05-02 14:05 ` luc.vanoostenryck at gmail dot com 2021-05-03 8:02 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-100377-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).