-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang] Worse code gen when default constructing with ()
than {}
#122560
Comments
Note that constructing with the C++20 syntax of |
@llvm/issue-subscribers-clang-codegen Author: David Stone (davidstone)
The following translation unit
long get();
void unused() noexcept;
struct s {
~s() {
if (m0 != 0) {
unused();
}
}
long m0 = 0;
long m1 = 0;
};
s f() {
#if defined USE_BRACES
auto x = s{};
#else
auto x = s();
#endif
x.m1 = get();
return x;
} Generates the following code when compiled with
but generates the following when compiled with
These correspond to the assembly
f():
push rbx
mov rbx, rdi
mov qword ptr [rdi], 0
call get()@<!-- -->PLT
mov qword ptr [rbx + 8], rax
mov rax, rbx
pop rbx
ret and without: f():
push rbx
mov rbx, rdi
xorps xmm0, xmm0
movups xmmword ptr [rdi], xmm0
call get()@<!-- -->PLT
mov qword ptr [rbx + 8], rax
mov rax, rbx
pop rbx
ret See it live: https://godbolt.org/z/hfcPeTsfo |
The following translation unit
Generates the following code when compiled with
-DUSE_BRACES -O3 -emit-llvm
:but generates the following when compiled with
-O3 -emit-llvm
:These correspond to the assembly
-DUSE_BRACES
:and without:
See it live: https://godbolt.org/z/hfcPeTsfo
The text was updated successfully, but these errors were encountered: