@@ -180,6 +180,7 @@ namespace {
180
180
bool tryJumpThreading (BranchInst *BI);
181
181
bool tailDuplicateObjCMethodCallSuccessorBlocks ();
182
182
bool simplifyAfterDroppingPredecessor (SILBasicBlock *BB);
183
+ bool addToWorklistAfterSplittingEdges (SILBasicBlock *BB);
183
184
184
185
bool simplifyBranchOperands (OperandValueArrayRef Operands);
185
186
bool simplifyBranchBlock (BranchInst *BI);
@@ -715,6 +716,18 @@ bool SimplifyCFG::simplifyAfterDroppingPredecessor(SILBasicBlock *BB) {
715
716
return false ;
716
717
}
717
718
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
+
718
731
static NullablePtr<EnumElementDecl>
719
732
getEnumCaseRecursive (SILValue Val, SILBasicBlock *UsedInBB, int RecursionDepth,
720
733
llvm::SmallPtrSetImpl<SILArgument *> &HandledArgs) {
@@ -1075,7 +1088,10 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
1075
1088
// the threaded and edge block to the worklist now that they (likely) can be
1076
1089
// simplified.
1077
1090
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 ());
1079
1095
1080
1096
// We may be able to simplify DestBB now that it has one fewer predecessor.
1081
1097
simplifyAfterDroppingPredecessor (DestBB);
@@ -2816,7 +2832,9 @@ bool SimplifyCFG::tailDuplicateObjCMethodCallSuccessorBlocks() {
2816
2832
Cloner.updateSSAAfterCloning ();
2817
2833
2818
2834
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 ());
2820
2838
}
2821
2839
return Changed;
2822
2840
}
0 commit comments