[llvm] [mlir] Verify threadlocal_address constraints (PR #87841)
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 11:40:48 PDT 2024
https://github.com/MatzeB updated https://github.com/llvm/llvm-project/pull/87841
>From be8299b04210edae9f1aa562f49ee1b994f668aa Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Fri, 5 Apr 2024 16:14:48 -0700
Subject: [PATCH 1/3] Verify threadlocal_address constraints
Check invariants for `llvm.threadlocal.address` intrinsic in IR
Verifier.
---
llvm/lib/IR/Verifier.cpp | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 64c59914cf2fc2..ac3d13f3d2b057 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6223,6 +6223,14 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
&Call);
break;
}
+ case Intrinsic::threadlocal_address: {
+ const Value &Arg0 = *Call.getArgOperand(0);
+ Check(isa<GlobalVariable>(Arg0),
+ "llvm.threadlocal.address first argument must be a GlobalVariable");
+ Check(cast<GlobalVariable>(Arg0).isThreadLocal(),
+ "llvm.threadlocal.address operand isThreadLocal() must no be false");
+ break;
+ }
};
// Verify that there aren't any unmediated control transfers between funclets.
>From f923274e2b8b9b42c75c442dcfd4441df7586380 Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Fri, 5 Apr 2024 17:25:24 -0700
Subject: [PATCH 2/3] Stricted langref wording; xfail test
---
llvm/docs/LangRef.rst | 2 +-
.../HipStdPar/unsupported-thread-local-indirect-use.ll | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 774729c5f0836e..aea3c2a3bbaffa 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -28119,7 +28119,7 @@ Syntax:
Arguments:
""""""""""
-The first argument is a pointer, which refers to a thread local global.
+The first argument is a thread local :ref:`global variable <globalvars>`.
Semantics:
""""""""""
diff --git a/llvm/test/Transforms/HipStdPar/unsupported-thread-local-indirect-use.ll b/llvm/test/Transforms/HipStdPar/unsupported-thread-local-indirect-use.ll
index 40014853d8ac52..960828c76f789a 100644
--- a/llvm/test/Transforms/HipStdPar/unsupported-thread-local-indirect-use.ll
+++ b/llvm/test/Transforms/HipStdPar/unsupported-thread-local-indirect-use.ll
@@ -1,5 +1,6 @@
; RUN: not opt -S -mtriple=amdgcn-amd-amdhsa -passes=hipstdpar-select-accelerator-code \
; RUN: %s 2>&1 | FileCheck %s
+; XFAIL: *
@tls = hidden thread_local addrspace(1) global i32 0, align 4
>From 8d686b130dff41352ebd8bf3c566a450098d1519 Mon Sep 17 00:00:00 2001
From: Matthias Braun <matze at braunis.de>
Date: Mon, 8 Apr 2024 11:27:53 -0700
Subject: [PATCH 3/3] adapt MLIR tests
---
mlir/test/Target/LLVMIR/Import/intrinsic.ll | 6 ++++--
mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir | 10 +++++++---
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/mlir/test/Target/LLVMIR/Import/intrinsic.ll b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
index 0cefb4f8983aa6..81a6eadbadd3fc 100644
--- a/mlir/test/Target/LLVMIR/Import/intrinsic.ll
+++ b/mlir/test/Target/LLVMIR/Import/intrinsic.ll
@@ -641,10 +641,12 @@ define void @expect_with_probability(i16 %0) {
ret void
}
+ at tls_var = dso_local thread_local global i32 0, align 4
+
; CHECK-LABEL: llvm.func @threadlocal_test
-define void @threadlocal_test(ptr %0) {
+define void @threadlocal_test() {
; CHECK: "llvm.intr.threadlocal.address"(%{{.*}}) : (!llvm.ptr) -> !llvm.ptr
- %local = call ptr @llvm.threadlocal.address.p0(ptr %0)
+ %local = call ptr @llvm.threadlocal.address.p0(ptr @tls_var)
ret void
}
diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
index 0013522582a727..858e5bdc449235 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -576,10 +576,14 @@ llvm.func @expect_with_probability(%arg0: i16) {
llvm.return
}
+llvm.mlir.global external thread_local @tls_var(0 : i32) {addr_space = 0 : i32, alignment = 4 : i64, dso_local} : i32
+
// CHECK-LABEL: @threadlocal_test
-llvm.func @threadlocal_test(%arg0 : !llvm.ptr) {
- // CHECK: call ptr @llvm.threadlocal.address.p0(ptr %{{.*}})
- "llvm.intr.threadlocal.address"(%arg0) : (!llvm.ptr) -> !llvm.ptr
+llvm.func @threadlocal_test() {
+ // CHECK: call ptr @llvm.threadlocal.address.p0(ptr @tls_var)
+ %0 = llvm.mlir.constant(0 : i32) : i32
+ %1 = llvm.mlir.addressof @tls_var : !llvm.ptr
+ "llvm.intr.threadlocal.address"(%1) : (!llvm.ptr) -> !llvm.ptr
llvm.return
}
More information about the llvm-commits
mailing list