@@ -1571,17 +1571,29 @@ bool SimplifyCFG::simplifyCondBrBlock(CondBranchInst *BI) {
1571
1571
1572
1572
// Simplify cond_br where both sides jump to the same blocks with the same
1573
1573
// args.
1574
- if (TrueArgs == FalseArgs && (TrueSide == FalseTrampolineDest ||
1575
- FalseSide == TrueTrampolineDest)) {
1576
- LLVM_DEBUG (llvm::dbgs () << " replace cond_br with same dests with br: "
1577
- << *BI);
1578
- SILBuilderWithScope (BI).createBranch (BI->getLoc (),
1579
- TrueTrampolineDest ? FalseSide : TrueSide, TrueArgs);
1574
+ auto condBrToBr = [&](OperandValueArrayRef branchArgs,
1575
+ SILBasicBlock *newDest) {
1576
+ LLVM_DEBUG (llvm::dbgs ()
1577
+ << " replace cond_br with same dests with br: " << *BI);
1578
+ SILBuilderWithScope (BI).createBranch (BI->getLoc (), newDest, branchArgs);
1580
1579
BI->eraseFromParent ();
1581
1580
addToWorklist (ThisBB);
1582
- addToWorklist (TrueSide);
1583
1581
++NumConstantFolded;
1584
- return true ;
1582
+ };
1583
+ if (TrueArgs == FalseArgs) {
1584
+ if (TrueTrampolineDest) {
1585
+ if (TrueTrampolineDest == FalseSide
1586
+ || TrueTrampolineDest == FalseTrampolineDest) {
1587
+ condBrToBr (TrueArgs, TrueTrampolineDest);
1588
+ removeIfDead (TrueSide);
1589
+ removeIfDead (FalseSide);
1590
+ return true ;
1591
+ }
1592
+ } else if (FalseTrampolineDest == TrueSide) {
1593
+ condBrToBr (TrueArgs, FalseTrampolineDest);
1594
+ removeIfDead (FalseSide);
1595
+ return true ;
1596
+ }
1585
1597
}
1586
1598
1587
1599
auto *TrueTrampolineBr = getTrampolineWithoutBBArgsTerminator (TrueSide);
0 commit comments