https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118276
Bug ID: 118276
Summary: Adding empty c'tor to struct of std::array and integer
improves codegen
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: benfrantzdale at gmail dot com
Target Milestone: ---
Given https://godbolt.org/z/exKd1snTM
```
struct S {
long int c[10] = {};
int x{};
#if MODE == 0
#elif MODE == 1
S() = default;
#elif MODE == 2
S() noexcept {}
#endif
};
```
I get different (!) and better(!) codegen for the `S() noexcept {}` version
than the other two versions.
Perf: https://quick-bench.com/q/9hMTq-umqhLawEZDMVXH4qKr6XU
I think (?) `S() noexcept {}` is semantically the same as `S() = default;` or
as no c'tor, so it's a surprise that `S() noexcept {}` leads to
```
pxor xmm0, xmm0
mov DWORD PTR [rdi+80], 0
mov rax, rdi
movups XMMWORD PTR [rdi], xmm0
movups XMMWORD PTR [rdi+16], xmm0
movups XMMWORD PTR [rdi+32], xmm0
movups XMMWORD PTR [rdi+48], xmm0
movups XMMWORD PTR [rdi+64], xmm0
ret
```
versus
```
mov rdx, rdi
xor eax, eax
mov ecx, 11
rep stosq
mov rax, rdx
ret
```
Furthermore, my sense is contemporary style is to provide no c'tor or `=
default;` rather than `S() noexcept {}`, so here the code with better style
performs worse for no apparent reason.