[mlir] Move the assertion to a valid place.
authorHanhan Wang <hanchung@google.com>
Thu, 3 Nov 2022 01:09:46 +0000 (18:09 -0700)
committerHanhan Wang <hanchung@google.com>
Fri, 4 Nov 2022 19:14:15 +0000 (12:14 -0700)
The defining Op may live in an unlinked block so its parent Op may be
null. Only assert it when the parent Op is not null.

Reviewed By: mravishankar

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

mlir/lib/Analysis/SliceAnalysis.cpp

index e343c47..4684ccf 100644 (file)
@@ -98,10 +98,11 @@ static void getBackwardSliceImpl(Operation *op,
       // TODO: determine whether we want to recurse backward into the other
       // blocks of parentOp, which are not technically backward unless they flow
       // into us. For now, just bail.
-      assert(parentOp->getNumRegions() == 1 &&
-             parentOp->getRegion(0).getBlocks().size() == 1);
-      if (backwardSlice->count(parentOp) == 0)
+      if (parentOp && backwardSlice->count(parentOp) == 0) {
+        assert(parentOp->getNumRegions() == 1 &&
+               parentOp->getRegion(0).getBlocks().size() == 1);
         getBackwardSliceImpl(parentOp, backwardSlice, filter);
+      }
     } else {
       llvm_unreachable("No definingOp and not a block argument.");
     }