public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Optimizing redundant calls to _tls_get_addr()
@ 2021-06-10 19:31 Roy Jacobson
  0 siblings, 0 replies; only message in thread
From: Roy Jacobson @ 2021-06-10 19:31 UTC (permalink / raw)
  To: gcc-help

Hi,

I've recently encountered a performance issue with gcc and accessing
thread-local storage. I've posted a question on SO:
https://stackoverflow.com/questions/67894898/why-doesnt-gcc-eliminate-successive-calls-to-tls-get-addr
with the details of the problem, which has unfortunately not been answered
yet.

In short, GCC will call _tls_get_addr() on each access to a tls variable
inside a function, even if the variable is local. I would expect that from
the second access onwards, the result from the first access can be cached
and used instead. This is also what clang will do with "-O3".

A person on SO has led me to this discussion on the gcc mailing list in
2012: https://gcc.gnu.org/legacy-ml/gcc/2012-10/msg00024.html

I wonder what it would take to implement this optimization given the
current state of GCC? Are there maybe any thread safety reasons I miss why
it can't be done?

Thanks,
Roy Jacobson

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-10 19:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 19:31 Optimizing redundant calls to _tls_get_addr() Roy Jacobson

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