public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/55812] New: Unnecessary TLS accesses
@ 2012-12-26 12:53 glisse at gcc dot gnu.org
  2012-12-26 15:44 ` [Bug tree-optimization/55812] " glisse at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2012-12-26 12:53 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55812

             Bug #: 55812
           Summary: Unnecessary TLS accesses
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: glisse@gcc.gnu.org
            Target: x86_64-linux-gnu


Hello,

TLS accesses are expensive, so as much as possible gcc should copy the address
to a local variable and use that instead. The following example may not be very
good, I am just trying to illustrate the issue.

#include <vector>
thread_local std::vector<int> v;
int main(){
  for(long i=0;i<400000000;++i){
    v.push_back(i);
  }
  return v.size();
}

compiled with g++ -std=c++11 -O2 -Wall -DNDEBUG. If I remove "thread_local",
the speed-up is about 20%. It seems to me that the compiler should get the
address of v once at the beginning of main and use that for the rest of the
function, and thus the performance difference should be negligible.

If I add "static" in front of "thread_local", the program fails to link, but my
gcc snapshot is a bit old (Nov 20) and I think I've already seen that reported.

I was surprised not to find any compiler option that would disable threads, so
I could write thread_local but not pay the price when compiling a
single-threaded program. Without -pthread, glibc uses cheap thread-unsafe
functions, but I still pay for TLS.


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

end of thread, other threads:[~2012-12-27  9:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-26 12:53 [Bug tree-optimization/55812] New: Unnecessary TLS accesses glisse at gcc dot gnu.org
2012-12-26 15:44 ` [Bug tree-optimization/55812] " glisse at gcc dot gnu.org
2012-12-26 21:55 ` [Bug target/55812] " pinskia at gcc dot gnu.org
2012-12-26 21:57 ` [Bug tree-optimization/55812] " pinskia at gcc dot gnu.org
2012-12-27  9:38 ` [Bug tree-optimization/55812] thread_local with either a ctor or dtor causes a function call every time through a loop glisse at gcc dot gnu.org

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