[mlir][sparse] fix crash when calling getTuple on non-sparse tensors.
authorPeiming Liu <peiming@google.com>
Fri, 11 Nov 2022 18:51:25 +0000 (18:51 +0000)
committerPeiming Liu <peiming@google.com>
Fri, 11 Nov 2022 21:15:44 +0000 (21:15 +0000)
This enables full sparse convolution codegen in D137298

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D137853

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorCodegen.cpp

index 499dc4c..d7dd824 100644 (file)
@@ -59,15 +59,16 @@ static void flattenOperands(ValueRange operands,
   // ==>
   // memref ..., c, memref ...
   for (auto operand : operands) {
-    if (auto tuple = getTuple(operand);
-        tuple && getSparseTensorEncoding(tuple->getResultTypes()[0]))
+    if (getSparseTensorEncoding(operand.getType())) {
+      auto tuple = getTuple(operand);
       // An unrealized_conversion_cast will be inserted by type converter to
       // inter-mix the gap between 1:N conversion between sparse tensors and
       // fields. In this case, take the operands in the cast and replace the
       // sparse tensor output with the flattened type array.
       flattened.append(tuple.getOperands().begin(), tuple.getOperands().end());
-    else
+    } else {
       flattened.push_back(operand);
+    }
   }
 }