[Mlir-commits] [mlir] 4a812b5 - Verify threadlocal_address constraints (#87841)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Apr 8 17:48:01 PDT 2024
Author: Matthias Braun
Date: 2024-04-08T17:47:57-07:00
New Revision: 4a812b5912d3149592cae195c9007b05649d9b41
URL: https://github.com/llvm/llvm-project/commit/4a812b5912d3149592cae195c9007b05649d9b41
DIFF: https://github.com/llvm/llvm-project/commit/4a812b5912d3149592cae195c9007b05649d9b41.diff
LOG: Verify threadlocal_address constraints (#87841)
Check invariants for `llvm.threadlocal.address` intrinsic in IR
Verifier.
Added:
Modified:
llvm/docs/LangRef.rst
llvm/lib/IR/Verifier.cpp
llvm/test/Transforms/HipStdPar/unsupported-thread-local-indirect-use.ll
mlir/test/Target/LLVMIR/Import/intrinsic.ll
mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
Removed:
################################################################################
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index a3722ecdf0c5ed..18fc46584d09ad 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -28120,7 +28120,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/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e63efe98a2e27e..4092f0cb12ffe9 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6224,6 +6224,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.
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
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..db5184a63d983a 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -576,10 +576,13 @@ 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.addressof @tls_var : !llvm.ptr
+ "llvm.intr.threadlocal.address"(%0) : (!llvm.ptr) -> !llvm.ptr
llvm.return
}
More information about the Mlir-commits
mailing list