[Mlir-commits] [mlir] [MLIR][CF] Avoid collapsing blocks which participate in cycles (PR #160783)
Matthias Springer
llvmlistbot at llvm.org
Sat Sep 27 03:20:52 PDT 2025
================
@@ -122,6 +122,18 @@ static LogicalResult collapseBranch(Block *&successor,
Block *successorDest = successorBranch.getDest();
if (successorDest == successor)
return failure();
+ // Don't try to collapse branches which participate in a cycle.
+ BranchOp nextBranch = dyn_cast<BranchOp>(successorDest->getTerminator());
+ llvm::DenseSet<Block *> visited{successorDest};
+ while (nextBranch) {
+ Block *nextBranchDest = nextBranch.getDest();
+ if (nextBranchDest == successor)
+ return failure();
+ else if (visited.contains(nextBranchDest))
+ break;
----------------
matthias-springer wrote:
Also, is the above `if (nextBranchDest == successor)` still necessary if you initialize the `visited` set with `successor`?
https://github.com/llvm/llvm-project/pull/160783
More information about the Mlir-commits
mailing list