diff --git a/mlir/lib/Transforms/CSE.cpp b/mlir/lib/Transforms/CSE.cpp --- a/mlir/lib/Transforms/CSE.cpp +++ b/mlir/lib/Transforms/CSE.cpp @@ -50,7 +50,9 @@ // If op has no regions, operation equivalence w.r.t operands alone is // enough. - if (lhs->getNumRegions() == 0 && rhs->getNumRegions() == 0) { + if ((lhs->getNumRegions() == 0 && rhs->getNumRegions() == 0) || + ((lhs->getNumRegions() == 1 && lhs->getRegion(0).empty()) && + (rhs->getNumRegions() == 1 && rhs->getRegion(0).empty()))) { return OperationEquivalence::isEquivalentTo( const_cast(lhsC), const_cast(rhsC), OperationEquivalence::exactValueMatch, @@ -264,7 +266,8 @@ // equality comparisons correctly among other things. It is also unclear // whether we would want to CSE such operations. if (op->getNumRegions() != 0 && - (op->getNumRegions() != 1 || !llvm::hasSingleElement(op->getRegion(0)))) + (op->getNumRegions() != 1 || + !(llvm::hasSingleElement(op->getRegion(0)) || op->getRegion(0).empty()))) return failure(); // Some simple use case of operation with memory side-effect are dealt with