Skip to content

Commit c6ff512

Browse files
aeubankststellar
authored andcommitted
[X86] Fix lowering TLS under darwin large code model (llvm#80907)
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. (cherry picked from commit 5a83bcc)
1 parent 02da751 commit c6ff512

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
@@ -18703,16 +18703,18 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const {
1870318703
if (Subtarget.isTargetDarwin()) {
1870418704
// Darwin only has one model of TLS. Lower to that.
1870518705
unsigned char OpFlag = 0;
18706-
unsigned WrapperKind = Subtarget.isPICStyleRIPRel() ?
18707-
X86ISD::WrapperRIP : X86ISD::Wrapper;
18706+
unsigned WrapperKind = 0;
1870818707

1870918708
// In PIC mode (unless we're in RIPRel PIC mode) we add an offset to the
1871018709
// global base reg.
1871118710
bool PIC32 = PositionIndependent && !Subtarget.is64Bit();
18712-
if (PIC32)
18711+
if (PIC32) {
1871318712
OpFlag = X86II::MO_TLVP_PIC_BASE;
18714-
else
18713+
WrapperKind = X86ISD::Wrapper;
18714+
} else {
1871518715
OpFlag = X86II::MO_TLVP;
18716+
WrapperKind = X86ISD::WrapperRIP;
18717+
}
1871618718
SDLoc DL(Op);
1871718719
SDValue Result = DAG.getTargetGlobalAddress(GA->getGlobal(), DL,
1871818720
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)