From 65c15cbd4a555c5fdf4f12ecfbba7a2702087e3f Mon Sep 17 00:00:00 2001 From: "William S. Moses" Date: Tue, 11 Jan 2022 13:33:43 -0500 Subject: [PATCH] [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 --- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 6 +++--- mlir/test/Dialect/LLVMIR/canonicalize.mlir | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td index 328ff9da3639..c6b52c722c2d 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:$addr, + let arguments = (ins Arg, "", [MemRead]>:$addr, OptionalAttr:$access_groups, OptionalAttr:$alias_scopes, OptionalAttr:$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:$addr, + Arg,"",[MemWrite]>:$addr, OptionalAttr:$access_groups, OptionalAttr:$alias_scopes, OptionalAttr:$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 7185920efe54..acc08c6453bc 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) { + %0 = llvm.load %x : !llvm.ptr + llvm.return +} + +llvm.mlir.global external @fp() : !llvm.ptr + +// CHECK-LABEL: addr_dce +// CHECK-NEXT: llvm.return +llvm.func @addr_dce(%x : !llvm.ptr) { + %0 = llvm.mlir.addressof @fp : !llvm.ptr> + llvm.return +}