https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80881
--- Comment #82 from LIU Hao <lh_mouse at 126 dot com> --- (In reply to Uroš Bizjak from comment #81) > (In reply to Julian Waters from comment #75) > > Any feedback on the new patch? > > I would propose you legitimize TLS address using get_thread_pointer (as is > the case with Eric's patch). Generic optimizers are then able to optimize > the access to the symbol and later rewrite the address to a TLS named > address space. > > Please consider this testcase (very relevant on linux, I don't know about > Windows): > > --cut here-- > extern __thread int i[8]; > > int foo (void) > { > return i[2] + i[4]; > } > --cut here-- > This also compiles fine with this patch (backported to GCC 14) which produces: (x86-32) ``` mov eax, DWORD PTR "__tls_index" mov edx, DWORD PTR fs:44 mov edx, DWORD PTR [edx+eax*4] mov eax, DWORD PTR "_i"@secrel32[edx+16] add eax, DWORD PTR "_i"@secrel32[edx+8] ret ``` (x86-64) ``` mov eax, DWORD PTR "_tls_index"[rip] mov rdx, QWORD PTR gs:88 mov rdx, QWORD PTR [rdx+rax*8] mov eax, DWORD PTR "i"@secrel32[rdx+16] add eax, DWORD PTR "i"@secrel32[rdx+8] ret ```