https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129052
--- Comment #5 from Uroš Bizjak <ubizjak at gmail dot com> --- Created attachment 66349 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66349&action=edit Patch in testing ix86_emit_tls_call seeds its set of live caller-saved registers from DF_LIVE_IN of the basic block and removes registers from it at REG_DEAD notes. Registers which are set inside the basic block were never added to the set, except for FLAGS. When the last live-in register died, the set became empty and the __tls_get_addr call for TLS_GD/TLS_LD_BASE was emitted right after that instruction, even if a call-clobbered register set earlier in the block was still live. For example, with -O2 -fPIC, a local register variable assigned to %r8 and read by a later inline asm had the call inserted in between, and the asm read the value clobbered by __tls_get_addr. Add the call-clobbered registers set by each instruction to the live set with note_stores, before the REG_DEAD and REG_UNUSED notes of that instruction are processedi, so a register which is set but never read doesn't keep the TLS call from being placed. Don't do this for TLSDESC, which only clobbers FLAGS. If such a register is still live at the end of the basic block, the call must be placed before the basic block, so use its immediate dominator instead of the dominator of the register's set blocks, which could be the same block and make no progress. Assisted-by: Claude Sonnet 5.5
