[Bug c++/88509] Missing optimization of tls initialization

2018-12-15 Thread rafael at espindo dot la
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88509

--- Comment #3 from Rafael Avila de Espindola  ---
(In reply to Jakub Jelinek from comment #2)
> I must say I don't understand your suggestion.  bar is not a pointer and its
> address is non-NULL no matter whether it has been already initialized or not.
> What kind of assembly you'd like to see for f?

Bar is not a pointer, but a guard variable for bar can be. It is initially null
and is set to bar's address once bar is initialized.

I think the assembly for f could be:

_Z1fv:
movq%fs:__guard_for_bar@tpoff, %rax 
testq   %rax, %rax
je  .L15
ret
.L15:
pushq   %rbx
movq%fs:0, %rbx
leaq_ZL3bar@tpoff(%rbx), %rdi
call_ZN3fooC1Ev
leaq_ZL3bar@tpoff(%rbx), %rax
movq%rax, %fs:__guard_for_bar@tpoff
popq%rbx
ret

The .L15 label could even be moved to a cold section.

[Bug c++/88509] Missing optimization of tls initialization

2018-12-15 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88509

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek  ---
I must say I don't understand your suggestion.  bar is not a pointer and its
address is non-NULL no matter whether it has been already initialized or not.
What kind of assembly you'd like to see for f?

[Bug c++/88509] Missing optimization of tls initialization

2018-12-14 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88509

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||missed-optimization

--- Comment #1 from Andrew Pinski  ---
>As far as I can tell this can be applied to any static tls variable

Only in functions which have non-vague linkage.  static varaibles in inline
functions have to have the same ABI across TUs and there might have some in
already compiled code ...