GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
i386

i386: Remove dead TLS local-dynamic base calls after scheduling

Eliminates unnecessary calls to `__tls_get_addr` for 64-bit TLS local-dynamic bases when they are no longer used, preventing compiler internal errors.

This commit addresses an issue where dead Thread Local Storage (TLS) calls for 64-bit local-dynamic bases were not being removed, leading to compiler internal errors (ICEs). The ix86_reorg function now identifies and removes these unused calls after the instruction scheduling phase. This prevents the compiler from encountering a %& pattern mismatch when no TLS symbol is found, thus resolving ICEs reported in PR128437.

In Details

For 64-bit TLS local-dynamic variables, the sequence involves a call to __tls_get_addr. When the last user of this call's output is removed by DCE (Dead Code Elimination) *after* instruction scheduling (sched2), the call itself remains. Since no subsequent DCE pass runs, the call persists. Its output template %& then fails to find a local-dynamic TLS symbol, causing an ICE. This patch introduces ix86_remove_dead_tls_ld_base in ix86_reorg (which runs after sched2) to remove such calls when their result is unused, resolving the ICE.

For Context
TLS
Thread Local Storage. A mechanism that provides each thread in a process with its own private copy of data. This allows threads to have thread-specific global variables.
local-dynamic TLS
A model for accessing thread-local data where the address of the thread-local variable is determined at runtime, typically involving a function call (like __tls_get_addr) to resolve the correct address for the current thread.
DCE
Dead Code Elimination. A compiler optimization pass that removes code that does not affect the program's output.
ICE
Internal Compiler Error. An error condition where the compiler encounters an unexpected state or inconsistency during compilation, causing it to abort.
sched2
Refers to the second instruction scheduling pass in GCC, responsible for reordering instructions to improve performance and pipeline utilization.
`%&`
A format specifier used in GCC's instruction descriptions, typically for matching symbols or operands within a specific context, such as finding a TLS symbol.
Filed Under: i386tlscompiler erroroptimization