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,12 @@ this->aliases[std::get<0>(entry)].insert(std::get<1>(entry)); }; + // Add additional aliases created by view changes to the alias list. + op->walk([&](ViewLikeOpInterface viewInterface) { + aliases[viewInterface.getViewSource()].insert( + viewInterface.getOperation()->getResult(0)); + }); + // 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,22 @@ // CHECK-NEXT: test.region_if_yield %[[ALLOC8]] // CHECK: dealloc %[[ALLOC0]] // CHECK-NEXT: return %[[ALLOC1]] + +// ----- + +// CHECK-LABEL: func @subview +func @subview(%arg0 : index, %arg1 : index, %arg2 : memref) { + %0 = alloc() : memref<64x4xf32, offset: 0, strides: [4, 1]> + %1 = subview %0[%arg0, %arg1][%arg0, %arg1][%arg0, %arg1] : + memref<64x4xf32, offset: 0, strides: [4, 1]> + to memref + "linalg.copy"(%1, %arg2) : + (memref, memref) -> () + return +} + +// CHECK-NEXT: %[[ALLOC:.*]] = alloc() +// CHECK-NEXT: subview +// CHECK-NEXT: linalg.copy +// CHECK-NEXT: dealloc %[[ALLOC]] +// CHECK-NEXT: return