https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97848
Bug ID: 97848
Summary: [missed optimization] tls init function check emitted
for consinit thread_local variables (C++20)
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
The code
=== begin code ===
extern thread_local constinit int x;
int foo_good() {
return x;
}
void set_foo(int y) {
x = y;
}
=== end code ===
knows that x will be statically initialized, but still emits the code to check
for the TLS init function and maybe call it:
=== begin objdump ===
foo_good():
movl $TLS init function for x, %eax
testq %rax, %rax
je .L7
subq $8, %rsp
call TLS init function for x
movq x@gottpoff(%rip), %rax
movl %fs:(%rax), %eax
addq $8, %rsp
ret
.L7:
movq x@gottpoff(%rip), %rax
movl %fs:(%rax), %eax
ret
set_foo(int):
movl $TLS init function for x, %eax
pushq %rbx
movl %edi, %ebx
testq %rax, %rax
je .L12
call TLS init function for x
.L12:
movq x@gottpoff(%rip), %rax
movl %ebx, %fs:(%rax)
popq %rbx
ret
=== end objdump ===
Instead, we should see the same output as for __thread_local.