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

* [Bug c++/97848] [missed optimization] tls init function check emitted for consinit thread_local variables (C++20)
  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 ` 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
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-11-16 10:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97848

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-11-16
           Keywords|                            |missed-optimization

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

* [Bug c++/97848] [missed optimization] tls init function check emitted for consinit thread_local variables (C++20)
  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
  2 siblings, 0 replies; 4+ messages in thread
From: avi@cloudius-systems.com @ 2021-03-23 19:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97848

--- Comment #1 from Avi Kivity <avi@cloudius-systems.com> ---
Still bad on trunk. Clang gets this right:

foo_good():                           # @foo_good()
        movq    x@GOTTPOFF(%rip), %rax
        movl    %fs:(%rax), %eax
        retq
set_foo(int):                            # @set_foo(int)
        movq    x@GOTTPOFF(%rip), %rax
        movl    %edi, %fs:(%rax)
        retq

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

* [Bug c++/97848] [missed optimization] tls init function check emitted for consinit thread_local variables (C++20)
  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
  2 siblings, 0 replies; 4+ messages in thread
From: avi at scylladb dot com @ 2021-11-29 15:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97848

Avi Kivity <avi at scylladb dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #2 from Avi Kivity <avi at scylladb dot com> ---
Fixed on trunk (12.0)

foo_good():
  movq x@gottpoff(%rip), %rax
  movl %fs:(%rax), %eax
  ret
set_foo(int):
  movq x@gottpoff(%rip), %rax
  movl %edi, %fs:(%rax)
  ret

^ 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).