public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pinskia at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/114258] 2 stores happen when copying from a const union (array) to an union
Date: Wed, 06 Mar 2024 18:23:47 +0000	[thread overview]
Message-ID: <bug-114258-4-rPIwx7lbHZ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114258-4@http.gcc.gnu.org/bugzilla/>

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-03-06
          Component|rtl-optimization            |middle-end
           Severity|normal                      |enhancement
            Summary|repeat store operation when |2 stores happen when
                   |copying a union             |copying from a const union
                   |                            |(array) to an union
     Ever confirmed|0                           |1
           Keywords|                            |missed-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
union U6 {
   short  f0;
   int f1;
};
union U6 g_13;
void func_1() {
  static const union U6 b[] = {{.f0 = 2}, {.f0 = 2}};
  g_13 = b[1];
}
```

It comes from the expansion of the assignment.


For aarch64 we have:
```
;; g_13 = b[1];

(insn 5 4 6 (set (reg:DI 101)
        (high:DI (symbol_ref:DI ("*.LANCHOR0") [flags 0x182])))
"/app/example.cpp":9:8 -1
     (nil))

(insn 6 5 7 (set (reg/f:DI 100)
        (lo_sum:DI (reg:DI 101)
            (symbol_ref:DI ("*.LANCHOR0") [flags 0x182])))
"/app/example.cpp":9:8 -1
     (expr_list:REG_EQUAL (symbol_ref:DI ("*.LANCHOR0") [flags 0x182])
        (nil)))

(insn 7 6 8 (set (mem/c:SI (reg/f:DI 100) [1 g_13D.4435+0 S4 A64])
        (const_int 0 [0])) "/app/example.cpp":9:8 -1
     (nil))

(insn 8 7 9 (set (reg:HI 102)
        (const_int 2 [0x2])) "/app/example.cpp":9:8 -1
     (nil))

(insn 9 8 10 (set (mem/c:HI (reg/f:DI 100) [2 g_13D.4435+0 S2 A64])
        (reg:HI 102)) "/app/example.cpp":9:8 -1
     (nil))

(insn 10 9 11 (set (mem/c:SI (reg/f:DI 100) [1 g_13D.4435+0 S4 A64])
        (const_int 0 [0])) "/app/example.cpp":9:8 -1
     (nil))

(insn 11 10 12 (set (reg:HI 103)
        (const_int 2 [0x2])) "/app/example.cpp":9:8 -1
     (nil))

(insn 12 11 0 (set (mem/c:HI (reg/f:DI 100) [2 g_13D.4435+0 S2 A64])
        (reg:HI 103)) "/app/example.cpp":9:8 -1
     (nil))
```

GCC could do better here in the expansion.

  reply	other threads:[~2024-03-06 18:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06 17:50 [Bug rtl-optimization/114258] New: repeat store operation when copying a union absoler at smail dot nju.edu.cn
2024-03-06 18:23 ` pinskia at gcc dot gnu.org [this message]
2024-03-07  8:15 ` [Bug middle-end/114258] 2 stores happen when copying from a const union (array) to an union 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-114258-4-rPIwx7lbHZ@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).