https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98110
--- Comment #12 from Florian Weimer <fw at gcc dot gnu.org> --- (In reply to Jakub Jelinek from comment #11) > Ah, RTL loop_invariant. Perhaps because the inline asm is buggy? > asm ("mov %%fs:%c1,%0" : "=r" (__self) : "i" (__builtin_offsetof (struct > pthread, header.self))); > The only input of the asm is the constant, so really nothing tells the > optimizers it can't move it arbitrarily. I think it needs to have some > memory input or clobber to properly model that it reads from unknown memory. Ahh, do you mean the THREAD_SELF macro? # define THREAD_SELF \ ({ struct pthread *__self; \ asm ("mov %%fs:%c1,%0" : "=r" (__self) \ : "i" (offsetof (struct pthread, header.self))); \ __self;}) I had only looked at the other macros. glibc relies on GCC optimizing away THREAD_SELF reads on x86-64 because most of the TCB access does not need it.