https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121352
--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> --- (In reply to Alexander Monakov from comment #1) > That patch deliberately takes care not to optimize in presence of the > attribute: > > /* Upgrade TLS access model based on optimized visibility status, > unless it was specified explicitly or no references remain. */ > if (DECL_THREAD_LOCAL_P (decl) > && !lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl)) > && vnode->ref_list.referring.length ()) > { The check isn't necessary since 1. -ftls-model=initial-exec can change tls_model without tls_model attribute. 2. Linker can change TLS access model at link-time. 3. LTO should perform the similar optimization. My C/C++ front-end patches: https://patchwork.sourceware.org/project/gcc/list/?series=50380 https://patchwork.sourceware.org/project/gcc/list/?series=50381 optimize TLS access model in all cases.