public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97848] New: [missed optimization] tls init function check emitted for consinit thread_local variables (C++20)
@ 2020-11-16  7:46 avi@cloudius-systems.com
  2020-11-16 10:50 ` [Bug c++/97848] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: avi@cloudius-systems.com @ 2020-11-16  7:46 UTC (permalink / raw)
  To: gcc-bugs

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: avi@cloudius-systems.com
  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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-29 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-16  7:46 [Bug c++/97848] New: [missed optimization] tls init function check emitted for consinit thread_local variables (C++20) avi@cloudius-systems.com
2020-11-16 10:50 ` [Bug c++/97848] " rguenth at gcc dot gnu.org
2021-03-23 19:59 ` avi@cloudius-systems.com
2021-11-29 15:32 ` avi at scylladb dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).