[llvm] [X86] Fix lowering TLS under darwin large code model (PR #80907)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 13:48:27 PST 2024


https://github.com/aeubanks created https://github.com/llvm/llvm-project/pull/80907

OpFlag and WrapperKind should be chosen consistently with each other in regards to PIC, otherwise we hit asserts later on.

Broken by c04a05d8.

Fixes #80831.

>From 5ef649d5b4284959810552c172c8e6720f1ff9ff Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Tue, 6 Feb 2024 21:45:25 +0000
Subject: [PATCH] [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 c04a05d8.

Fixes #80831.
---
 llvm/lib/Target/X86/X86ISelLowering.cpp | 10 ++++++----
 llvm/test/CodeGen/X86/tls-models.ll     |  1 +
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9a9b0680acc20..b5b76c66c2e49 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -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),
diff --git a/llvm/test/CodeGen/X86/tls-models.ll b/llvm/test/CodeGen/X86/tls-models.ll
index fc8e302338d96..8de9de15a5f06 100644
--- a/llvm/test/CodeGen/X86/tls-models.ll
+++ b/llvm/test/CodeGen/X86/tls-models.ll
@@ -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



More information about the llvm-commits mailing list