[mlir][sparse] Simplifying Merger::expContainsTensor
authorwren romano <2998727+wrengr@users.noreply.github.com>
Wed, 29 Mar 2023 23:36:14 +0000 (16:36 -0700)
committerwren romano <2998727+wrengr@users.noreply.github.com>
Fri, 7 Apr 2023 19:32:47 +0000 (12:32 -0700)
`expContainsTensor` used to call `expIsTensor` to short-circuit the recursive calls; however, the very first thing `expContainsTensor` does is to check `expIsTensor`, so the short-circuiting code just causes the function to check that condition redundantly.

Depends On D146684

Reviewed By: aartbik

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

mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp

index a79bfbb..8bdff8d 100644 (file)
@@ -454,6 +454,7 @@ bool Merger::onlyDenseDiff(LatPointId i, LatPointId j) const {
 
 bool Merger::expContainsTensor(ExprId e, TensorId t) const {
   const auto &expr = exp(e);
+  // First we check `expIsTensor`.
   if (expr.kind == TensorExp::Kind::kTensor)
     return expr.tensor == t;
 
@@ -462,15 +463,11 @@ bool Merger::expContainsTensor(ExprId e, TensorId t) const {
     return false;
   case ExpArity::kUnary: {
     const ExprId e0 = expr.children.e0;
-    if (expIsTensor(e0, t))
-      return true;
     return expContainsTensor(e0, t);
   }
   case ExpArity::kBinary: {
     const ExprId e0 = expr.children.e0;
     const ExprId e1 = expr.children.e1;
-    if (expIsTensor(e0, t) || expIsTensor(e1, t))
-      return true;
     return expContainsTensor(e0, t) || expContainsTensor(e1, t);
   }
   }