Skip to content

Commit f61e5ec

Browse files
committed
[X86] Avoid data16 prefix for lea in x32 mode
The ABI demands a data16 prefix for lea in 64-bit LP64 mode, but not in 64-bit ILP32 mode. In both modes this prefix would ordinarily be ignored, but the instructions may be changed by the linker to instructions that are affected by the prefix. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D93157
1 parent a482337 commit f61e5ec

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/lib/Target/X86/X86MCInstLower.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,8 @@ void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
979979
NoAutoPaddingScope NoPadScope(*OutStreamer);
980980
bool Is64Bits = MI.getOpcode() != X86::TLS_addr32 &&
981981
MI.getOpcode() != X86::TLS_base_addr32;
982+
bool Is64BitsLP64 = MI.getOpcode() == X86::TLS_addr64 ||
983+
MI.getOpcode() == X86::TLS_base_addr64;
982984
MCContext &Ctx = OutStreamer->getContext();
983985

984986
MCSymbolRefExpr::VariantKind SRVK;
@@ -1012,7 +1014,7 @@ void X86AsmPrinter::LowerTlsAddr(X86MCInstLower &MCInstLowering,
10121014

10131015
if (Is64Bits) {
10141016
bool NeedsPadding = SRVK == MCSymbolRefExpr::VK_TLSGD;
1015-
if (NeedsPadding)
1017+
if (NeedsPadding && Is64BitsLP64)
10161018
EmitAndCountInstruction(MCInstBuilder(X86::DATA16_PREFIX));
10171019
EmitAndCountInstruction(MCInstBuilder(X86::LEA64r)
10181020
.addReg(X86::RDI)

llvm/test/CodeGen/X86/pic.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ entry:
285285
; CHECK-I686-DAG: calll ___tls_get_addr@PLT
286286
; CHECK-I686-DAG: leal tlssrcgd@TLSGD(,%ebx), %eax
287287
; CHECK-I686-DAG: calll ___tls_get_addr@PLT
288+
; CHECK-X32-NOT: data16
288289
; CHECK-X32-DAG: leaq tlsdstgd@TLSGD(%rip), %rdi
289290
; CHECK-X32-DAG: callq __tls_get_addr@PLT
290291
; CHECK-X32-DAG: leaq tlsptrgd@TLSGD(%rip), %rdi

0 commit comments

Comments
 (0)