https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114258
Andrew Pinski 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 ---
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.