diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp --- a/llvm/lib/Target/X86/X86MCInstLower.cpp +++ b/llvm/lib/Target/X86/X86MCInstLower.cpp @@ -979,6 +979,8 @@ NoAutoPaddingScope NoPadScope(*OutStreamer); bool Is64Bits = MI.getOpcode() != X86::TLS_addr32 && MI.getOpcode() != X86::TLS_base_addr32; + bool Is64BitsLP64 = MI.getOpcode() == X86::TLS_addr64 || + MI.getOpcode() == X86::TLS_base_addr64; MCContext &Ctx = OutStreamer->getContext(); MCSymbolRefExpr::VariantKind SRVK; @@ -1012,7 +1014,7 @@ if (Is64Bits) { bool NeedsPadding = SRVK == MCSymbolRefExpr::VK_TLSGD; - if (NeedsPadding) + if (NeedsPadding && Is64BitsLP64) EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX)); EmitAndCountInstruction(MCInstBuilder(X86::LEA64r) .addReg(X86::RDI) diff --git a/llvm/test/CodeGen/X86/pic.ll b/llvm/test/CodeGen/X86/pic.ll --- a/llvm/test/CodeGen/X86/pic.ll +++ b/llvm/test/CodeGen/X86/pic.ll @@ -285,6 +285,7 @@ ; CHECK-I686-DAG: calll ___tls_get_addr@PLT ; CHECK-I686-DAG: leal tlssrcgd@TLSGD(,%ebx), %eax ; CHECK-I686-DAG: calll ___tls_get_addr@PLT +; CHECK-X32-NOT: data16 ; CHECK-X32-DAG: leaq tlsdstgd@TLSGD(%rip), %rdi ; CHECK-X32-DAG: callq __tls_get_addr@PLT ; CHECK-X32-DAG: leaq tlsptrgd@TLSGD(%rip), %rdi