From bdfb4b04deba41b5c7651de7b7a7e68504ce89c5 Mon Sep 17 00:00:00 2001 From: donald chen Date: Tue, 8 Jul 2025 09:13:26 +0000 Subject: [PATCH] [mlir][scf] fix getSuccessorRegions func in scf.forall 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. --- mlir/lib/Dialect/SCF/IR/SCF.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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()); } //===----------------------------------------------------------------------===//