[llvm] [GlobalISel] Implement threadlocal.address translation (PR #206908)
Ömer Sinan Ağacan via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 1 10:52:54 PDT 2026
https://github.com/osa1 updated https://github.com/llvm/llvm-project/pull/206908
>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 1/3] [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
+...
>From 48e03f6e10dcfd679920ea9ec5b63cb6abd9121c 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 13:05:33 +0100
Subject: [PATCH 2/3] Update test
---
.../AArch64/GlobalISel/threadlocal-address.ll | 21 ++++++++++++++
.../GlobalISel/threadlocal-address.mir | 28 -------------------
2 files changed, 21 insertions(+), 28 deletions(-)
create mode 100644 llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll
delete mode 100644 llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll b/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll
new file mode 100644
index 0000000000000..fbf4b56b532b4
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc -mtriple aarch64-apple-macosx -global-isel -stop-after=irtranslator %s -o - | FileCheck %s
+
+ at tls_var = external thread_local global ptr
+
+define ptr @f() {
+ ; 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
+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) }
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir b/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir
deleted file mode 100644
index 27f191beef715..0000000000000
--- a/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.mir
+++ /dev/null
@@ -1,28 +0,0 @@
-# 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
-...
>From 27c328f47c5f361aada104220cf2efb93075f2c7 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 18:52:36 +0100
Subject: [PATCH 3/3] Address comment
---
llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll b/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll
index fbf4b56b532b4..b0e608edb9f5c 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/threadlocal-address.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
-; RUN: llc -mtriple aarch64-apple-macosx -global-isel -stop-after=irtranslator %s -o - | FileCheck %s
+; RUN: llc -global-isel -mtriple aarch64-apple-macosx -stop-after=irtranslator %s -o - | FileCheck %s
@tls_var = external thread_local global ptr
More information about the llvm-commits
mailing list