diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp --- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp +++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp @@ -545,6 +545,8 @@ SideEffects::DefaultResource::get()); effects.emplace_back(MemoryEffects::Write::get(), output(), SideEffects::DefaultResource::get()); + effects.emplace_back(MemoryEffects::Allocate::get(), output(), + SideEffects::DefaultResource::get()); } namespace { diff --git a/mlir/test/Transforms/buffer-deallocation.mlir b/mlir/test/Transforms/buffer-deallocation.mlir --- a/mlir/test/Transforms/buffer-deallocation.mlir +++ b/mlir/test/Transforms/buffer-deallocation.mlir @@ -1207,3 +1207,18 @@ }) : () -> (i32) "test.terminator"() : () -> () } + +// ----- + +// CHECK-LABEL: func @dealloc_existing_clones +// CHECK: (%[[ARG0:.*]]: memref, %[[ARG1:.*]]: memref) +// CHECK: %[[RES0:.*]] = memref.clone %[[ARG0]] +// CHECK: %[[RES1:.*]] = memref.clone %[[ARG1]] +// CHECK-NOT: memref.dealloc %[[RES0]] +// CHECK: memref.dealloc %[[RES1]] +// CHECK: return %[[RES0]] +func @dealloc_existing_clones(%arg0: memref, %arg1: memref) -> memref { + %0 = memref.clone %arg0 : memref to memref + %1 = memref.clone %arg1 : memref to memref + return %0 : memref +}