[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
This commit is contained in:
William S. Moses 2022-01-11 13:33:43 -05:00
parent 694fd10659
commit 65c15cbd4a
2 changed files with 21 additions and 3 deletions

View File

@ -356,7 +356,7 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [NoSideEffect]> {
} }
def LLVM_LoadOp : LLVM_Op<"load">, MemoryOpWithAlignmentAndAttributes { 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>:$access_groups,
OptionalAttr<SymbolRefArrayAttr>:$alias_scopes, OptionalAttr<SymbolRefArrayAttr>:$alias_scopes,
OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes, OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes,
@ -390,7 +390,7 @@ def LLVM_LoadOp : LLVM_Op<"load">, MemoryOpWithAlignmentAndAttributes {
def LLVM_StoreOp : LLVM_Op<"store">, MemoryOpWithAlignmentAndAttributes { def LLVM_StoreOp : LLVM_Op<"store">, MemoryOpWithAlignmentAndAttributes {
let arguments = (ins LLVM_LoadableType:$value, let arguments = (ins LLVM_LoadableType:$value,
LLVM_PointerTo<LLVM_LoadableType>:$addr, Arg<LLVM_PointerTo<LLVM_LoadableType>,"",[MemWrite]>:$addr,
OptionalAttr<SymbolRefArrayAttr>:$access_groups, OptionalAttr<SymbolRefArrayAttr>:$access_groups,
OptionalAttr<SymbolRefArrayAttr>:$alias_scopes, OptionalAttr<SymbolRefArrayAttr>:$alias_scopes,
OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes, OptionalAttr<SymbolRefArrayAttr>:$noalias_scopes,
@ -861,7 +861,7 @@ def UnnamedAddr : LLVM_EnumAttr<
let cppNamespace = "::mlir::LLVM"; 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 arguments = (ins FlatSymbolRefAttr:$global_name);
let results = (outs LLVM_Type:$res); let results = (outs LLVM_Type:$res);

View File

@ -104,3 +104,21 @@ func @llvm_constant() -> i32 {
// CHECK: return %[[RES]] // CHECK: return %[[RES]]
return %2 : i32 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
}