[Mlir-commits] [mlir] Add non-temporal support for LLVM masked loads (PR #104598)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Aug 16 07:45:26 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-mlir
Author: Giuseppe Rossini (giuseros)
<details>
<summary>Changes</summary>
This PR is adding non-temporal support to masked load as a Boolean (defaulted to 0) attribute. Non temporal load is quite an important feature for masked loads to make the intrinsic usable from high level compilers
---
Full diff: https://github.com/llvm/llvm-project/pull/104598.diff
2 Files Affected:
- (modified) mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td (+9-5)
- (modified) mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir (+4-1)
``````````diff
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
index 2e1635e590cad6..22803c8ee59faa 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -842,22 +842,26 @@ def LLVM_GetActiveLaneMaskOp
/// Create a call to Masked Load intrinsic.
def LLVM_MaskedLoadOp : LLVM_OneResultIntrOp<"masked.load"> {
let arguments = (ins LLVM_AnyPointer:$data, LLVM_VectorOf<I1>:$mask,
- Variadic<LLVM_AnyVector>:$pass_thru, I32Attr:$alignment);
+ Variadic<LLVM_AnyVector>:$pass_thru, I32Attr:$alignment,
+ DefaultValuedAttr<BoolAttr, "false">:$nontemporal);
let results = (outs LLVM_AnyVector:$res);
let assemblyFormat =
"operands attr-dict `:` functional-type(operands, results)";
string llvmBuilder = [{
- $res = $pass_thru.empty() ? builder.CreateMaskedLoad(
+ auto *inst = $pass_thru.empty() ? builder.CreateMaskedLoad(
$_resultType, $data, llvm::Align($alignment), $mask) :
builder.CreateMaskedLoad(
$_resultType, $data, llvm::Align($alignment), $mask, $pass_thru[0]);
- }];
+ $res = inst;
+ }] #setNonTemporalMetadataCode;
string mlirBuilder = [{
+ auto *intrinInst = dyn_cast<llvm::IntrinsicInst>(inst);
$res = $_builder.create<LLVM::MaskedLoadOp>($_location,
- $_resultType, $data, $mask, $pass_thru, $_int_attr($alignment));
+ $_resultType, $data, $mask, $pass_thru, $_int_attr($alignment),
+ mlir::BoolAttr::get($_op->getContext(), intrinInst->hasMetadata(llvm::LLVMContext::MD_nontemporal)));
}];
- list<int> llvmArgIndices = [0, 2, 3, 1];
+ list<int> llvmArgIndices = [0, 2, 3, 1, -1];
}
/// Create a call to Masked Store intrinsic.
diff --git a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
index 7878aa5ee46d4f..14af06fa93992b 100644
--- a/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
+++ b/mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir
@@ -417,8 +417,11 @@ llvm.func @masked_load_store_intrinsics(%A: !llvm.ptr, %mask: vector<7xi1>) {
// CHECK: call <7 x float> @llvm.masked.load.v7f32.p0(ptr %{{.*}}, i32 1, <7 x i1> %{{.*}}, <7 x float> poison)
%a = llvm.intr.masked.load %A, %mask { alignment = 1: i32} :
(!llvm.ptr, vector<7xi1>) -> vector<7xf32>
+ // CHECK: call <7 x float> @llvm.masked.load.v7f32.p0(ptr %{{.*}}, i32 1, <7 x i1> %{{.*}}, <7 x float> poison), !nontemporal !1
+ %b = llvm.intr.masked.load %A, %mask { alignment = 1: i32, nontemporal=1 :i1} :
+ (!llvm.ptr, vector<7xi1>) -> vector<7xf32>
// CHECK: call <7 x float> @llvm.masked.load.v7f32.p0(ptr %{{.*}}, i32 1, <7 x i1> %{{.*}}, <7 x float> %{{.*}})
- %b = llvm.intr.masked.load %A, %mask, %a { alignment = 1: i32} :
+ %c = llvm.intr.masked.load %A, %mask, %a { alignment = 1: i32} :
(!llvm.ptr, vector<7xi1>, vector<7xf32>) -> vector<7xf32>
// CHECK: call void @llvm.masked.store.v7f32.p0(<7 x float> %{{.*}}, ptr %0, i32 {{.*}}, <7 x i1> %{{.*}})
llvm.intr.masked.store %b, %A, %mask { alignment = 1: i32} :
``````````
</details>
https://github.com/llvm/llvm-project/pull/104598
More information about the Mlir-commits
mailing list