aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Springer <springerm@google.com>2023-02-15 16:40:42 +0100
committerMatthias Springer <springerm@google.com>2023-02-15 16:54:23 +0100
commit6dd9d18204d2b1b0fc0480c9153f6d5e320b87d5 (patch)
tree5d8cc354f2be0b185119389bf64e53c2947b3e3c
parent4f15267d3dd797a15901fe9352f0d5fa121b9095 (diff)
downloadllvm-6dd9d18204d2b1b0fc0480c9153f6d5e320b87d5.zip
llvm-6dd9d18204d2b1b0fc0480c9153f6d5e320b87d5.tar.gz
llvm-6dd9d18204d2b1b0fc0480c9153f6d5e320b87d5.tar.bz2
[mlir][linalg] Fix insertion point bug in D144022
This should have been part of D144022.
-rw-r--r--mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp4
-rw-r--r--mlir/test/Dialect/Linalg/transform-op-bufferize-to-allocation.mlir22
2 files changed, 25 insertions, 1 deletions
diff --git a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
index 261ad97..1915c2a 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/ConvertToDestinationStyle.cpp
@@ -264,6 +264,7 @@ Value linalg::bufferizeToAllocation(RewriterBase &rewriter, PadOp padOp,
// Create buffer allocation.
Value alloc =
createAllocationForTensor(rewriter, loc, padOp.getResult(), memorySpace);
+ rewriter.setInsertionPointAfter(alloc.getDefiningOp());
// Create linalg.fill or linalg.generic.
Operation *fillOp = movePaddingToFillOrGenericOp(rewriter, loc, padOp, alloc);
@@ -344,7 +345,7 @@ Value linalg::bufferizeToAllocation(RewriterBase &rewriter, Value value,
if (auto bbArg = value.dyn_cast<BlockArgument>()) {
rewriter.setInsertionPointToStart(bbArg.getOwner());
} else {
- rewriter.setInsertionPoint(value.getDefiningOp());
+ rewriter.setInsertionPointAfter(value.getDefiningOp());
}
Location loc = value.getLoc();
@@ -352,6 +353,7 @@ Value linalg::bufferizeToAllocation(RewriterBase &rewriter, Value value,
Value alloc = createAllocationForTensor(rewriter, loc, value, memorySpace);
// Create memref.tensor_store.
+ rewriter.setInsertionPointAfter(alloc.getDefiningOp());
rewriter.create<memref::TensorStoreOp>(loc, value, alloc);
// Create bufferization.to_tensor with "restrict" and "writable". The returned
diff --git a/mlir/test/Dialect/Linalg/transform-op-bufferize-to-allocation.mlir b/mlir/test/Dialect/Linalg/transform-op-bufferize-to-allocation.mlir
index be277ba..0b3942f 100644
--- a/mlir/test/Dialect/Linalg/transform-op-bufferize-to-allocation.mlir
+++ b/mlir/test/Dialect/Linalg/transform-op-bufferize-to-allocation.mlir
@@ -110,3 +110,25 @@ transform.sequence failures(propagate) {
// Make sure that One-Shot Bufferize can bufferize the rest.
transform.bufferization.one_shot_bufferize %arg1
}
+
+// -----
+
+// CHECK-LABEL: func @materialization_of_opresult(
+// CHECK: %[[t:.*]] = "dummy.some_op"
+// CHECK: %[[alloc:.*]] = memref.alloc(%{{.*}}) : memref<?x10xindex, 4>
+// CHECK: memref.tensor_store %[[t]], %[[alloc]]
+// CHECK: %[[r:.*]] = bufferization.to_tensor %[[alloc]]
+// CHECK: return %[[r]]
+func.func @materialization_of_opresult(%idx: index) -> tensor<?x10xindex> {
+ %t = "dummy.some_op"() : () -> (tensor<?x10xindex>)
+ return %t : tensor<?x10xindex>
+}
+
+transform.sequence failures(propagate) {
+^bb1(%arg1: !pdl.operation):
+ %0 = transform.structured.match ops{["dummy.some_op"]} in %arg1 : (!pdl.operation) -> !pdl.operation
+ %1 = transform.get_result %0[0] : (!pdl.operation) -> !transform.any_value
+ %2 = transform.structured.bufferize_to_allocation %1 {memory_space = 4}
+}
+
+