Hello! Attached patch cleans legitimize_tls_address and corresponding expanders to call gen_tls_dynamic_gnu2_{32,64} directly in case of TARGET_GNU2_TLS target. The patch also changes unique REG_EQUIV note to __tls_get_addr call to UNSPEC (the same approach MIPS does) instead of some strange nested EXPR_LISTs. Additionally, ix86_tls_get_address is now used only in i386.c, so it can be declared static. The patch does not introduce any functional change, leaving also previous ICE on 64bit targets with -mcmodel=large and -mtls-dialect=gnu: tls.c:6:1: error: unrecognizable insn: (call_insn/u 5 4 6 3 (parallel [ (set (reg:DI 0 ax) (call:DI (mem:QI (symbol_ref:DI ("__tls_get_addr")) [0 S1 A8]) (const_int 0 [0]))) (unspec:DI [ (symbol_ref:DI ("tls_gd") [flags 0x12] ) ] UNSPEC_TLS_GD) ]) tls.c:5 -1 (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000]) (nil)) (nil)) The test (tls.c), used to check all TLS models is attached to the message. I plan to convert it to proper dg test... ;) 2011-05-11 Uros Bizjak * config/i386/i386.c (legitimize_tls_address) : Call gen_tls_dynamic_gnu2_{32,64} expanders directly for TARGET_GNU2_TLS. Determine pic and __tls_get_addr symbol reference here. Update call to gen_tls_global_dynamic_{32,64} for added arguments. : Call gen_tls_dynamic_gnu2_{32,64} expanders directly for TARGET_GNU2_TLS. Determine __tls_get_addr symbol reference here. Update call to gen_tls_local_dynamic_base_{32,64} for added arguments. Attach unique UNSPEC REG_EQUIV to libcall block. (ix86_tls_get_addr): Declare static. * config/i386/i386-protos.h (ix86_tls_get_addr): Remove declaration. * config/i386/i386.md (tls_global_dynamic_32): Add operand 2 and 3. Do not determine pic and __tls_get_addr symbol reference here. Do not call gen_tls_dynamic_gnu2_32 for TARGET_GNU2_TLS. (tls_local_dynamic_base_32): Ditto for operands 1 and 2. (tls_global_dynamic_64): Add operand 2. Do not determine __tls_get_addr symbol reference here. Do not call gen_tls_dynamic_gnu2_64 for TARGET_GNU2_TLS here. (tls_local_dynamic_base64): Ditto for operand 1. Patch was tested on x86_64-pc-linux-gnu {,-m32} and committed to mainline SVN. Uros.