public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/107051] New: redundant loads when copying a union
@ 2022-09-27 11:25 absoler at smail dot nju.edu.cn
2022-09-27 13:18 ` [Bug rtl-optimization/107051] " rguenth at gcc dot gnu.org
2024-03-27 0:21 ` absoler at smail dot nju.edu.cn
0 siblings, 2 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2022-09-27 11:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107051
Bug ID: 107051
Summary: redundant loads when copying a union
Product: gcc
Version: 12.1.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: ---
for this code:
union U2 {
unsigned f0;
char * f1;
};
union U2 g_284[2] = {{0UL},{0xC2488F72L}};
int e;
void func_1() {
union U2 c = {7};
int32_t *d[2];
for (; e;)
*d[1] = 0;
g_284[0] = c = g_284[1];
}
compile it with gcc-12.1.0 -O1, and generate:
0000000000401186 <func_1>:
401186: 83 3d fb 8c 00 00 00 cmpl $0x0,0x8cfb(%rip) #
409e88 <e>
40118d: 74 02 je 401191 <func_1+0xb>
40118f: eb fe jmp 40118f <func_1+0x9>
401191: 8b 15 d1 2e 00 00 mov 0x2ed1(%rip),%edx #
404068 <g_284+0x8>
401197: 48 b8 00 00 00 00 ff movabs $0xffffffff00000000,%rax
40119e: ff ff ff
4011a1: 48 23 05 c0 2e 00 00 and 0x2ec0(%rip),%rax #
404068 <g_284+0x8>
4011a8: 48 09 d0 or %rdx,%rax
4011ab: 48 89 05 ae 2e 00 00 mov %rax,0x2eae(%rip) #
404060 <g_284>
4011b2: c3 retq
I don't understand why clearing the low 4 bytes of g_284[1].f1 and then or it
with g_284[1].f0, because it should be equal?
and for the next example, we can see the both fields of g_303 have been loaded
and written to g:
union U0 {
short f0;
int f3;
};
union U0 g_303 = {0x9B86L};
union U0 g;
int a,b;
void func_1() {
union U0 d[1] = {1};
for (; a;)
for (; b;)
;
g = d[0] = g_303;
}
under gcc-12.1.0 -O1:
0000000000401186 <func_1>:
401186: 83 3d ff 8c 00 00 00 cmpl $0x0,0x8cff(%rip) #
409e8c <a>
40118d: 74 02 je 401191 <func_1+0xb>
40118f: eb fe jmp 40118f <func_1+0x9>
401191: 8b 05 c9 2e 00 00 mov 0x2ec9(%rip),%eax #
404060 <g_303>
401197: 66 8b 05 c2 2e 00 00 mov 0x2ec2(%rip),%ax # 404060
<g_303>
40119e: 89 05 ec 8c 00 00 mov %eax,0x8cec(%rip) #
409e90 <g>
4011a4: c3 retq
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug rtl-optimization/107051] redundant loads when copying a union
2022-09-27 11:25 [Bug rtl-optimization/107051] New: redundant loads when copying a union absoler at smail dot nju.edu.cn
@ 2022-09-27 13:18 ` rguenth at gcc dot gnu.org
2024-03-27 0:21 ` absoler at smail dot nju.edu.cn
1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-27 13:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107051
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2022-09-27
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
With -O2 I see
func_1:
.LFB0:
.cfi_startproc
movl e(%rip), %eax
testl %eax, %eax
je .L2
.L3:
jmp .L3
.p2align 4,,10
.p2align 3
.L2:
movq g_284+8(%rip), %rax
movq %rax, g_284(%rip)
ret
note that with -O1 we retain
c = g_284[1];
c$f0_3 = g_284[1].f0;
c.f0 = c$f0_3;
g_284[0] = c;
after GIMPLE optimization which possibly explains this compared to
c = g_284[1];
g_284[0] = c;
with -O2.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug rtl-optimization/107051] redundant loads when copying a union
2022-09-27 11:25 [Bug rtl-optimization/107051] New: redundant loads when copying a union absoler at smail dot nju.edu.cn
2022-09-27 13:18 ` [Bug rtl-optimization/107051] " rguenth at gcc dot gnu.org
@ 2024-03-27 0:21 ` absoler at smail dot nju.edu.cn
1 sibling, 0 replies; 3+ messages in thread
From: absoler at smail dot nju.edu.cn @ 2024-03-27 0:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107051
--- Comment #2 from absoler at smail dot nju.edu.cn ---
(In reply to Richard Biener from comment #1)
> With -O2 I see
>
> func_1:
> .LFB0:
> .cfi_startproc
> movl e(%rip), %eax
> testl %eax, %eax
> je .L2
> .L3:
> jmp .L3
> .p2align 4,,10
> .p2align 3
> .L2:
> movq g_284+8(%rip), %rax
> movq %rax, g_284(%rip)
> ret
>
> note that with -O1 we retain
>
> c = g_284[1];
> c$f0_3 = g_284[1].f0;
> c.f0 = c$f0_3;
> g_284[0] = c;
>
> after GIMPLE optimization which possibly explains this compared to
>
> c = g_284[1];
> g_284[0] = c;
>
> with -O2.
for gcc-13.2.0 -O2, it seems still forget to remove the load for this reduced
case:
```
union U0 {
short f1;
int f2;
};
union U0 g1, g2;
volatile int flag;
void func_1() {
union U0 d[1] = {{.f1 = 1}};
for (; flag;)
;
d[0] = g2;
g1 = d[0];
}
```
```
func_1:
.LFB0:
.cfi_startproc
.p2align 4,,10
.p2align 3
.L2:
movl flag(%rip), %eax
testl %eax, %eax
jne .L2
movl g2(%rip), %eax
movw g2(%rip), %ax
movl %eax, g1(%rip)
ret
.cfi_endproc
```
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-27 0:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-27 11:25 [Bug rtl-optimization/107051] New: redundant loads when copying a union absoler at smail dot nju.edu.cn
2022-09-27 13:18 ` [Bug rtl-optimization/107051] " rguenth at gcc dot gnu.org
2024-03-27 0:21 ` absoler at smail dot nju.edu.cn
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).