[Mlir-commits] [mlir] [mlir][sparse] clone a empty sparse tensor when fuse convert into pro… (PR #92158)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue May 14 11:25:08 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir-sparse
Author: Peiming Liu (PeimingLiu)
<details>
<summary>Changes</summary>
…ducer.
---
Full diff: https://github.com/llvm/llvm-project/pull/92158.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp (+7-7)
``````````diff
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
index da635c2578885..5fb009e3eebe6 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
@@ -302,17 +302,17 @@ struct FoldConvertIntoProducer : public OpRewritePattern<ConvertOp> {
!producer.getResult(0).hasOneUse()) {
return failure();
}
+ // Clone the materialization operation, but update the result to sparse.
+ rewriter.setInsertionPoint(producer);
+ Operation *init = producer.getDpsInitOperand(0)->get().getDefiningOp();
+ Operation *cloned = rewriter.clone(*init);
+ cloned->getResult(0).setType(op.getResult().getType());
+
rewriter.modifyOpInPlace(producer, [&]() {
+ producer.getDpsInitsMutable().assign(cloned->getResults());
producer.getResult(0).setType(op.getResult().getType());
});
- Operation *materializeOp =
- producer.getDpsInitOperand(0)->get().getDefiningOp();
-
- rewriter.modifyOpInPlace(materializeOp, [&]() {
- materializeOp->getResult(0).setType(op.getResult().getType());
- });
-
rewriter.replaceAllOpUsesWith(op, producer);
op->erase();
``````````
</details>
https://github.com/llvm/llvm-project/pull/92158
More information about the Mlir-commits
mailing list