[Mlir-commits] [mlir] 65c15cb - [MLIR][LLVM] Add MemRead/MemWrite behavior to llvm store/load/addressof ops
William S. Moses
llvmlistbot at llvm.org
Tue Jan 11 11:55:35 PST 2022
Author: William S. Moses
Date: 2022-01-11T14:55:30-05:00
New Revision: 65c15cbd4a555c5fdf4f12ecfbba7a2702087e3f
URL: https://github.com/llvm/llvm-project/commit/65c15cbd4a555c5fdf4f12ecfbba7a2702087e3f
DIFF: https://github.com/llvm/llvm-project/commit/65c15cbd4a555c5fdf4f12ecfbba7a2702087e3f.diff
LOG: [MLIR][LLVM] Add MemRead/MemWrite behavior to llvm store/load/addressof ops
This patch adds corresponding memory effects to mlir llvm-dialect load/store/addressof ops, which thus enables canonicalizations of those ops (like dead code elimination) that rely on the effect interface
Reviewed By: mehdi_amini
Differential Revision: https://reviews.llvm.org/D117041
Added:
Modified:
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
mlir/test/Dialect/LLVMIR/canonicalize.mlir
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 328ff9da3639a..c6b52c722c2d6 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -356,7 +356,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [NoSideEffect]> {
}
def LLVM_LoadOp : LLVM_Op<"load">, MemoryOpWithAlignmentAndAttributes {
- let arguments = (ins LLVM_PointerTo<LLVM_LoadableType>:$addr,
+ let arguments = (ins Arg<LLVM_PointerTo<LLVM_LoadableType>, "", [MemRead]>:$addr,
OptionalAttr<SymbolRefArrayAttr>:$access_groups,
OptionalAttr<SymbolRefArrayAttr>:$alias_scopes,
OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes,
@@ -390,7 +390,7 @@ def LLVM_LoadOp : LLVM_Op<"load">, MemoryOpWithAlignmentAndAttributes {
def LLVM_StoreOp : LLVM_Op<"store">, MemoryOpWithAlignmentAndAttributes {
let arguments = (ins LLVM_LoadableType:$value,
- LLVM_PointerTo<LLVM_LoadableType>:$addr,
+ Arg<LLVM_PointerTo<LLVM_LoadableType>,"",[MemWrite]>:$addr,
OptionalAttr<SymbolRefArrayAttr>:$access_groups,
OptionalAttr<SymbolRefArrayAttr>:$alias_scopes,
OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes,
@@ -861,7 +861,7 @@ def UnnamedAddr : LLVM_EnumAttr<
let cppNamespace = "::mlir::LLVM";
}
-def LLVM_AddressOfOp : LLVM_Op<"mlir.addressof"> {
+def LLVM_AddressOfOp : LLVM_Op<"mlir.addressof", [NoSideEffect]> {
let arguments = (ins FlatSymbolRefAttr:$global_name);
let results = (outs LLVM_Type:$res);
diff --git a/mlir/test/Dialect/LLVMIR/canonicalize.mlir b/mlir/test/Dialect/LLVMIR/canonicalize.mlir
index 7185920efe54b..acc08c6453bcd 100644
--- a/mlir/test/Dialect/LLVMIR/canonicalize.mlir
+++ b/mlir/test/Dialect/LLVMIR/canonicalize.mlir
@@ -104,3 +104,21 @@ func @llvm_constant() -> i32 {
// CHECK: return %[[RES]]
return %2 : i32
}
+
+// -----
+
+// CHECK-LABEL: load_dce
+// CHECK-NEXT: llvm.return
+llvm.func @load_dce(%x : !llvm.ptr<i8>) {
+ %0 = llvm.load %x : !llvm.ptr<i8>
+ llvm.return
+}
+
+llvm.mlir.global external @fp() : !llvm.ptr<i8>
+
+// CHECK-LABEL: addr_dce
+// CHECK-NEXT: llvm.return
+llvm.func @addr_dce(%x : !llvm.ptr<i8>) {
+ %0 = llvm.mlir.addressof @fp : !llvm.ptr<ptr<i8>>
+ llvm.return
+}
More information about the Mlir-commits
mailing list