@@ -180,6 +180,7 @@ namespace {
180180 bool tryJumpThreading (BranchInst *BI);
181181 bool tailDuplicateObjCMethodCallSuccessorBlocks ();
182182 bool simplifyAfterDroppingPredecessor (SILBasicBlock *BB);
183+ bool addToWorklistAfterSplittingEdges (SILBasicBlock *BB);
183184
184185 bool simplifyBranchOperands (OperandValueArrayRef Operands);
185186 bool simplifyBranchBlock (BranchInst *BI);
@@ -715,6 +716,18 @@ bool SimplifyCFG::simplifyAfterDroppingPredecessor(SILBasicBlock *BB) {
715716 return false ;
716717}
717718
719+ // / This is called after \p BB has been cloned during jump-threading
720+ // / (tail-duplication) and the new critical edge on its successor has been
721+ // / split. This is necessary to continue jump-threading through the split
722+ // / critical edge (since we only jump-thread one block at a time).
723+ bool SimplifyCFG::addToWorklistAfterSplittingEdges (SILBasicBlock *BB) {
724+ addToWorklist (BB);
725+ for (auto *succBB : BB->getSuccessorBlocks ()) {
726+ addToWorklist (succBB);
727+ }
728+ return false ;
729+ }
730+
718731static NullablePtr<EnumElementDecl>
719732getEnumCaseRecursive (SILValue Val, SILBasicBlock *UsedInBB, int RecursionDepth,
720733 llvm::SmallPtrSetImpl<SILArgument *> &HandledArgs) {
@@ -1075,7 +1088,10 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
10751088 // the threaded and edge block to the worklist now that they (likely) can be
10761089 // simplified.
10771090 addToWorklist (SrcBB);
1078- addToWorklist (Cloner.getNewBB ());
1091+
1092+ // Simplify the cloned block and continue jump-threading through its new
1093+ // successors edges.
1094+ addToWorklistAfterSplittingEdges (Cloner.getNewBB ());
10791095
10801096 // We may be able to simplify DestBB now that it has one fewer predecessor.
10811097 simplifyAfterDroppingPredecessor (DestBB);
@@ -2816,7 +2832,9 @@ bool SimplifyCFG::tailDuplicateObjCMethodCallSuccessorBlocks() {
28162832 Cloner.updateSSAAfterCloning ();
28172833
28182834 Changed = true ;
2819- addToWorklist (Cloner.getNewBB ());
2835+ // Simplify the cloned block and continue tail duplicating through its new
2836+ // successors edges.
2837+ addToWorklistAfterSplittingEdges (Cloner.getNewBB ());
28202838 }
28212839 return Changed;
28222840}
0 commit comments