https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128437
--- Comment #23 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-14 branch has been updated by Uros Bizjak <[email protected]>: https://gcc.gnu.org/g:c39f9359a6ee4b76724427d00ac26cb936fda7e4 commit r14-13028-gc39f9359a6ee4b76724427d00ac26cb936fda7e4 Author: Uros Bizjak <[email protected]> Date: Sat Nov 7 11:34:49 2026 +0000 i386: Don't output dead TLS LD base sequences [PR128437] The 64-bit TLS local-dynamic base sequence is a const call to __tls_get_addr whose template uses '%&', which needs a local-dynamic TLS symbol from some other insn in the function. The last such reference can be deleted after RA while the call survives: DCE doesn't delete calls in sched2, a dead spill store can still use the call's result, and REG_UNUSED notes may not be recomputed at all when sched2 or DCE doesn't run. The function then has no local-dynamic TLS symbol left, and '%&' ICEs. Fix this by making the output independent of what other passes deleted. The only users of the local-dynamic base are the "base + sym@dtpoff" forms, and all of them contain the TLS symbol. So if get_some_local_dynamic_name finds no symbol, nothing can use the base, and the insn only has to define its result register. Output "xor" instead of the lea and call in this case, in both 64-bit patterns and in the 32-bit pattern, which can be kept alive by a dead spill store in the same way. FLAGS_REG is clobbered by the call patterns, and explicitly by the 32-bit pattern. Assisted-by: Claude Sonnet 5.5 PR target/128437 gcc/ChangeLog: * config/i386/i386.md (*tls_local_dynamic_base_32_gnu): Output xor of the result register when no local-dynamic TLS symbol is left. (*tls_local_dynamic_base_64_<mode>): Ditto. (*tls_local_dynamic_base_64_largepic): Ditto. gcc/testsuite/ChangeLog: * g++.target/i386/pr128437.C: New test. (cherry picked from commit 45d15ffd7de445fdb993550dee54304d20b053d1)
