[llvm] [GlobalISel] Implement threadlocal.address translation (PR #206908)

Ömer Sinan Ağacan via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 01:39:06 PDT 2026


https://github.com/osa1 created https://github.com/llvm/llvm-project/pull/206908

Use the same lowering as sdag.

>From 939d07ee2506509ed7501e005e114358b3320bd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= <omeragacan at gmail.com>
Date: Wed, 1 Jul 2026 09:37:49 +0100
Subject: [PATCH] [GlobalISel] Implement threadlocal.address translation

---
 llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp  |  3 +-
 .../GlobalISel/threadlocal-address.mir        | 28 +++++++++++++++++++
 2 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir

diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 9567162275e4c..97e64230b73d9 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2522,7 +2522,8 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
   case Intrinsic::annotation:
   case Intrinsic::ptr_annotation:
   case Intrinsic::launder_invariant_group:
-  case Intrinsic::strip_invariant_group: {
+  case Intrinsic::strip_invariant_group:
+  case Intrinsic::threadlocal_address: {
     // Drop the intrinsic, but forward the value.
     MIRBuilder.buildCopy(getOrCreateVReg(CI),
                          getOrCreateVReg(*CI.getArgOperand(0)));
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir b/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir
new file mode 100644
index 0000000000000..27f191beef715
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir
@@ -0,0 +1,28 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mtriple aarch64-apple-macosx -global-isel -run-pass=irtranslator %s -o - | FileCheck %s
+--- |
+  @tls_var = external thread_local global ptr
+
+  define ptr @f() {
+  entry:
+    %p = call ptr @llvm.threadlocal.address.p0(ptr @tls_var)
+    ret ptr %p
+  }
+
+  ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
+
+  attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
+...
+---
+name:            f
+tracksRegLiveness: true
+isSSA:           true
+body:             |
+  ; CHECK-LABEL: name: f
+  ; CHECK: bb.1.entry:
+  ; CHECK-NEXT:   [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @tls_var
+  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(p0) = COPY [[GV]](p0)
+  ; CHECK-NEXT:   $x0 = COPY [[COPY]](p0)
+  ; CHECK-NEXT:   RET_ReallyLR implicit $x0
+...



More information about the llvm-commits mailing list