[Mlir-commits] [mlir] [MLIR][CF] Avoid collapsing blocks which participate in cycles (PR #160783)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Fri Sep 26 00:33:27 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.
+ Block *currBlock = successorDest;
+ BranchOp nextBranch = dyn_cast<BranchOp>(currBlock->getTerminator());
+ while (nextBranch) {
----------------
benwu25 wrote:
I see your argument, but weirdly enough, I have already written this testcase (`@delayed_3_cycle`), and somehow it terminates. I think that `A -> B -> C` is first canonicalized as just `C` by the `simplifyBrToBlockWithSinglePred`, so then when we collapse on `C` it somehow works out.
However, if `B` has another predecessor, maybe the loop will be broken.
https://github.com/llvm/llvm-project/pull/160783
More information about the Mlir-commits
mailing list