Skip to content

Commit 5ef649d

Browse files
committed
[X86] Fix lowering TLS under darwin large code model
OpFlag and WrapperKind should be chosen consistently with each other in regards to PIC, otherwise we hit asserts later on. Broken by c04a05d. Fixes llvm#80831.
1 parent 942cb24 commit 5ef649d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18710,16 +18710,18 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const {
1871018710
if (Subtarget.isTargetDarwin()) {
1871118711
// Darwin only has one model of TLS. Lower to that.
1871218712
unsigned char OpFlag = 0;
18713-
unsigned WrapperKind = Subtarget.isPICStyleRIPRel() ?
18714-
X86ISD::WrapperRIP : X86ISD::Wrapper;
18713+
unsigned WrapperKind = 0;
1871518714

1871618715
// In PIC mode (unless we're in RIPRel PIC mode) we add an offset to the
1871718716
// global base reg.
1871818717
bool PIC32 = PositionIndependent && !Subtarget.is64Bit();
18719-
if (PIC32)
18718+
if (PIC32) {
1872018719
OpFlag = X86II::MO_TLVP_PIC_BASE;
18721-
else
18720+
WrapperKind = X86ISD::Wrapper;
18721+
} else {
1872218722
OpFlag = X86II::MO_TLVP;
18723+
WrapperKind = X86ISD::WrapperRIP;
18724+
}
1872318725
SDLoc DL(Op);
1872418726
SDValue Result = DAG.getTargetGlobalAddress(GA->getGlobal(), DL,
1872518727
GA->getValueType(0),

llvm/test/CodeGen/X86/tls-models.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
; Darwin always uses the same model.
77
; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck -check-prefix=DARWIN %s
8+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -code-model=large | FileCheck -check-prefix=DARWIN %s
89

910
@external_gd = external thread_local global i32
1011
@internal_gd = internal thread_local global i32 42

0 commit comments

Comments
 (0)