i386: Fix dead TLS LD base sequences for PR128437
Fixes incorrect generation of 32/64-bit TLS local-dynamic base sequences on i386, preventing ICEs and ensuring correctness.
This commit addresses an issue in the i386 backend (PR128437) where dead 64-bit TLS local-dynamic base calls could persist and cause ICEs due to missing notes or deleted reloads. The fix makes the generation of these sequences independent of other optimization passes by ensuring that if no local-dynamic TLS symbol is found, a simpler ‘xor’ instruction is emitted instead of a full call. This also applies to 32-bit patterns and removes a now-unnecessary helper function.
In Details
This commit fixes PR128437 by ensuring that the output of TLS local-dynamic base accessors (tls_local_dynamic_base_32_gnu, tls_local_dynamic_base_64*) in config/i386/i386.md is robust against optimizations like DSE and DCE removing necessary reload information. Previously, missing REG_UNUSED notes on calls could lead to dead lea/call insns. The fix replaces these with a simple xor of the result register when get_some_local_dynamic_name returns no symbol, effectively making the insn a no-op if its result is unused. It also removes the redundant ix86_remove_dead_tls_ld_base function.
- TLS
- Thread-Local Storage. A mechanism allowing each thread in a multithreaded program to have its own copy of a variable.
- local-dynamic TLS
- A type of Thread-Local Storage where the variable's address is determined at runtime. Access involves calculating an offset relative to a base address specific to the thread.
- PIC
- Position-Independent Code. Code that can be loaded and executed at any memory address without modification, typically used for shared libraries.
- ICE
- Internal Compiler Error. An error condition within the compiler itself, indicating a bug in the compiler's logic.
- DCE
- Dead Code Elimination. An optimization pass that removes code that has no effect on the program's output.
- DSE
- Dead Store Elimination. An optimization pass that removes stores to memory that are never read before being overwritten.
- PR
- Problem Report. A bug report filed against the GCC project.