public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/114258] New: repeat store operation when copying a union
@ 2024-03-06 17:50 absoler at smail dot nju.edu.cn
  2024-03-06 18:23 ` [Bug middle-end/114258] 2 stores happen when copying from a const union (array) to an union pinskia at gcc dot gnu.org
  2024-03-07  8:15 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-03-06 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114258
           Summary: repeat store operation when copying a union
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: absoler at smail dot nju.edu.cn
  Target Milestone: ---

Hi, here's the code and generated binary compiled with gcc-13.2.0 -O2:

```
// https://godbolt.org/z/jsMhcbKnh

union U6 {
   int  f0;
   long long  f1;
   int  f2;
};

union U8 {
   int  f0;
   const long long  f1;
   const long long  f2;
};
union U6 g_13 = {.f0 = 0xE13F5E3DL};
union U8 g_189 = {.f0 = 0x959411BBL};

int d = 0;
int a;
void func_1() {
  const union U6 b[] = {{.f0 = 2}, {.f0 = 2}};
  for (; d;)
    a = 0;
  g_189.f0 &= (g_13 = b[1], 5);
}
```

```
func_1:
 mov    0x2f02(%rip),%eax        # 404028 <d>
 test   %eax,%eax
 je     401130 <func_1+0x10>
 jmp    40112a <func_1+0xa>
 nopl   0x0(%rax)
 movq   $0x0,0x2edd(%rip)        # 404018 <g_13>
 andl   $0x5,0x2ece(%rip)        # 404010 <g_189>
 movl   $0x2,0x2ecc(%rip)        # 404018 <g_13>
 ret
```

we can see that the first write to `g_13` could be removed to improve
performance.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-07  8:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [Bug middle-end/114258] 2 stores happen when copying from a const union (array) to an union pinskia at gcc dot gnu.org
2024-03-07  8:15 ` rguenth at gcc dot gnu.org

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).