public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "avi@cloudius-systems.com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/97848] New: [missed optimization] tls init function check emitted for consinit thread_local variables (C++20)
Date: Mon, 16 Nov 2020 07:46:30 +0000	[thread overview]
Message-ID: <bug-97848-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2020-11-16  7:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16  7:46 avi@cloudius-systems.com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97848-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).