[Mlir-commits] [mlir] [mlir][sparse] simplify ConvertOp rewriting rules (PR #68350)
Yinying Li
llvmlistbot at llvm.org
Wed Oct 11 09:18:25 PDT 2023
================
@@ -1066,6 +1066,44 @@ OpFoldResult ConvertOp::fold(FoldAdaptor adaptor) {
return {};
}
+bool ConvertOp::directConvertable() {
+ if (isSortCOOConvert())
+ return false;
+
+ SparseTensorType srcStt = getSparseTensorType(getSource());
+ SparseTensorType dstStt = getSparseTensorType(getDest());
+
+ // We can always directly convert to unordered sparse tensor or dense tensor
+ // since dense tensor support random access.
+ if (dstStt.isAllDense() || !dstStt.isAllOrdered())
+ return true;
+
+ if (srcStt.isAllOrdered() && dstStt.isAllOrdered() &&
+ srcStt.hasSameDimToLvl(dstStt)) {
+ return true;
+ }
+
+ // Source and dest tensors are ordered in different ways. We only do direct
+ // dense to sparse conversion when the dense input is defined by a sparse
+ // constant. Note that we can theoritically always directly convert from dense
----------------
yinying-lisa-li wrote:
typo: theoretically?
https://github.com/llvm/llvm-project/pull/68350
More information about the Mlir-commits
mailing list