diff --git a/mlir/lib/Transforms/BufferPlacement.cpp b/mlir/lib/Transforms/BufferPlacement.cpp --- a/mlir/lib/Transforms/BufferPlacement.cpp +++ b/mlir/lib/Transforms/BufferPlacement.cpp @@ -142,6 +142,13 @@ this->aliases[std::get<0>(entry)].insert(std::get<1>(entry)); }; + // TODO: After providing an aliasing-operation-effects interface, this can + // be removed. + // Add an alias created by a MemRefCastOp to the alias list. + op->walk([&](MemRefCastOp memRefCastOp) { + aliases[memRefCastOp.getOperand()].insert(memRefCastOp); + }); + // Query all branch interfaces to link block argument aliases. op->walk([&](BranchOpInterface branchInterface) { Block *parentBlock = branchInterface.getOperation()->getBlock(); diff --git a/mlir/test/Transforms/buffer-placement.mlir b/mlir/test/Transforms/buffer-placement.mlir --- a/mlir/test/Transforms/buffer-placement.mlir +++ b/mlir/test/Transforms/buffer-placement.mlir @@ -914,3 +914,19 @@ // CHECK-NEXT: test.region_if_yield %[[ALLOC8]] // CHECK: dealloc %[[ALLOC0]] // CHECK-NEXT: return %[[ALLOC1]] + +// ----- + +// CHECK-LABEL: func @memref_cast_op +func @memref_cast_op(%arg0: memref<2xf32>) { + %0 = alloc() : memref<2xf32> + %1 = memref_cast %0 : memref<2xf32> to memref + "linalg.copy"(%1, %arg0) : (memref, memref<2xf32>) -> () + return +} + +// CHECK-NEXT: %[[ALLOC:.*]] = alloc() +// CHECK: memref_cast +// CHECK: linalg.copy +// CHECK-NEXT: dealloc %[[ALLOC]] +// CHECK-NEXT: return