https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93897
Bug ID: 93897
Summary: Poor trivial structure initialization code.
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: maxim.yegorushkin at gmail dot com
Target Milestone: ---
The following code:
#include <cstdint>
struct B {
std::int64_t x;
std::int32_t y;
std::int32_t z;
};
B f(std::int64_t x, std::int32_t y, std::int32_t z) {
return {x, y, z};
}
Compiled with `gcc -O3 -std=gnu++17 -march=skylake` generates the following
assembly:
f(long, int, int):
mov QWORD PTR [rsp-16], 0
mov QWORD PTR [rsp-24], rdi
vmovdqa xmm1, XMMWORD PTR [rsp-24]
vpinsrd xmm0, xmm1, esi, 2
vpinsrd xmm2, xmm0, edx, 3
vmovdqa XMMWORD PTR [rsp-24], xmm2
mov rax, QWORD PTR [rsp-24]
mov rdx, QWORD PTR [rsp-16]
ret
Which looks a bit excessive.
Whereas when compiled with `clang-9.0 -O3 -std=gnu++17 -march=skylake` it
produces the expected:
f(long, int, int):
mov rax, rdi
shl rdx, 32
mov ecx, esi
or rdx, rcx
ret
https://gcc.godbolt.org/z/udsiyF