Skip to content

Commit 3f1e827

Browse files
committed
[mlir] Linalg : do not forward memrefs to outputs when do bufferization
Example: ``` %0 = linalg.init_tensor : tensor<...> %1 = linalg.generic ... outs(%0: tensor<...>) %2 = linalg.generic ... outs(%0: tensor<...>) ``` Memref allocated as a result of `init_tensor` bufferization can be incorrectly overwritten by the second linalg.generic operation Reviewed By: silvas Differential Revision: https://reviews.llvm.org/D100921
1 parent ac30379 commit 3f1e827

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

mlir/lib/Dialect/Linalg/Transforms/Bufferize.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ allocateBuffersForResults(Location loc, LinalgOp linalgOp, ValueRange outputs,
5959
continue;
6060
}
6161

62-
if (auto alloc = resultTensor.getDefiningOp<memref::AllocOp>()) {
63-
resultBuffers.push_back(resultTensor);
64-
continue;
65-
}
6662
// Allocate buffers for statically-shaped results.
6763
if (memrefType.hasStaticShape()) {
6864
resultBuffers.push_back(b.create<memref::AllocOp>(loc, memrefType));

mlir/test/Dialect/Linalg/bufferize.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func @basic(%arg0: tensor<4xf32>) -> tensor<4xf32> {
4545
// CHECK: #map = affine_map<(d0) -> (d0)>
4646
// CHECK-LABEL: func @init_tensor(
4747
// CHECK-SAME: %[[IN:.*]]: tensor<?xf32>, %[[SIZE:.*]]: index)
48-
// CHECK: %[[OUT_BUF:.*]] = memref.alloc(%[[SIZE]]) : memref<?xf32>
4948
// CHECK: %[[MEMREF:.*]] = memref.buffer_cast %[[IN]] : memref<?xf32>
49+
// CHECK: %[[OUT_BUF:.*]] = memref.alloc(%[[SIZE]]) : memref<?xf32>
5050
// CHECK: linalg.generic
5151
// CHECK-SAME: ins(%[[MEMREF]] : memref<?xf32>)
5252
// CHECK-SAME: outs(%[[OUT_BUF]] : memref<?xf32>) {

0 commit comments

Comments
 (0)