diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp index 5a3bd984530db..2e0a7b85af756 100644 --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -1927,11 +1927,13 @@ void ForallOp::getCanonicalizationPatterns(RewritePatternSet &results, /// not a constant. void ForallOp::getSuccessorRegions(RegionBranchPoint point, SmallVectorImpl ®ions) { - // Both the operation itself and the region may be branching into the body or - // back into the operation itself. It is possible for loop not to enter the - // body. - regions.push_back(RegionSuccessor(&getRegion())); - regions.push_back(RegionSuccessor()); + // In accordance with the semantics of forall, its body is executed in + // parallel by multiple threads. We should not expect to branch back into + // the forall body after the region's execution is complete. + if (point.isParent()) + regions.push_back(RegionSuccessor(&getRegion())); + else + regions.push_back(RegionSuccessor()); } //===----------------------------------------------------------------------===//