public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "chfast at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/109667] New: [12/13/14 Regression] Unnecessary temporary storage used for 32-byte struct
Date: Fri, 28 Apr 2023 11:46:11 +0000	[thread overview]
Message-ID: <bug-109667-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109667

            Bug ID: 109667
           Summary: [12/13/14 Regression] Unnecessary temporary storage
                    used for 32-byte struct
           Product: gcc
           Version: 12.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: chfast at gmail dot com
  Target Milestone: ---

Reduced reproducer:

struct i256 {
    long v[4];
};
void assign(struct i256 *v, long z) {
    struct i256 r = {};
    for (int i = 0; i < 1; ++i) 
        r.v[i] = z;
    *v = r;
}

https://godbolt.org/z/avM74o3r6

The compiler allocates temporary storage on stack for `r`:

assign:
        pxor    xmm0, xmm0
        mov     QWORD PTR [rsp-40], rsi
        movups  XMMWORD PTR [rsp-32], xmm0
        movdqa  xmm1, XMMWORD PTR [rsp-40]
        mov     QWORD PTR [rsp-16], 0
        movdqa  xmm2, XMMWORD PTR [rsp-24]
        movups  XMMWORD PTR [rdi], xmm1
        movups  XMMWORD PTR [rdi+16], xmm2
        ret

Regression since 12. The 11 compiles nicely to:

assign:
        mov     QWORD PTR [rdi], rsi
        mov     QWORD PTR [rdi+8], 0
        mov     QWORD PTR [rdi+16], 0
        mov     QWORD PTR [rdi+24], 0
        ret

             reply	other threads:[~2023-04-28 11:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-28 11:46 chfast at gmail dot com [this message]
2023-04-28 12:27 ` [Bug tree-optimization/109667] " rguenth at gcc dot gnu.org
2023-05-02  9:45 ` jakub at gcc dot gnu.org
2023-05-02  9:56 ` jakub at gcc dot gnu.org
2023-05-08 12:27 ` 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-109667-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: link
Be 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).