https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98110
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> --- 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.