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

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 03:37:11 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-globalisel

Author: Ömer Sinan Ağacan (osa1)

<details>
<summary>Changes</summary>

Use the same lowering as sdag.

---
Full diff: https://github.com/llvm/llvm-project/pull/206908.diff


2 Files Affected:

- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+2-1) 
- (added) llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir (+28) 


``````````diff
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
+...

``````````

</details>


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


More information about the llvm-commits mailing list