Skip to content

Commit

Permalink
[X86] Fix lowering TLS under darwin large code model (llvm#80907)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aeubanks authored Feb 7, 2024
1 parent bb531c9 commit 5a83bcc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
10 changes: 6 additions & 4 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18710,16 +18710,18 @@ X86TargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const {
if (Subtarget.isTargetDarwin()) {
// Darwin only has one model of TLS. Lower to that.
unsigned char OpFlag = 0;
unsigned WrapperKind = Subtarget.isPICStyleRIPRel() ?
X86ISD::WrapperRIP : X86ISD::Wrapper;
unsigned WrapperKind = 0;

// In PIC mode (unless we're in RIPRel PIC mode) we add an offset to the
// global base reg.
bool PIC32 = PositionIndependent && !Subtarget.is64Bit();
if (PIC32)
if (PIC32) {
OpFlag = X86II::MO_TLVP_PIC_BASE;
else
WrapperKind = X86ISD::Wrapper;
} else {
OpFlag = X86II::MO_TLVP;
WrapperKind = X86ISD::WrapperRIP;
}
SDLoc DL(Op);
SDValue Result = DAG.getTargetGlobalAddress(GA->getGlobal(), DL,
GA->getValueType(0),
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/X86/tls-models.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

@external_gd = external thread_local global i32
@internal_gd = internal thread_local global i32 42
Expand Down

0 comments on commit 5a83bcc

Please sign in to comment.