[Mlir-commits] [mlir] Add non-temporal support for LLVM masked loads (PR #104598)
Giuseppe Rossini
llvmlistbot at llvm.org
Fri Aug 16 07:44:58 PDT 2024
https://github.com/giuseros created https://github.com/llvm/llvm-project/pull/104598
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
>From 1c201daa98265888b576407f22a0e26e5d746cdc Mon Sep 17 00:00:00 2001
From: Giuseppe Rossini <giuseppe.rossini at amd.com>
Date: Fri, 16 Aug 2024 15:42:24 +0100
Subject: [PATCH] Add non-temporal support for LLVM masked loads
---
.../mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td | 14 +++++++++-----
mlir/test/Target/LLVMIR/llvmir-intrinsics.mlir | 5 ++++-
2 files changed, 13 insertions(+), 6 deletions(-)
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} :
More information about the Mlir-commits
mailing list