Skip to content

Commit fe928d5

Browse files
committed
SimplifyCFG: fix an infinite jump-threading loop.
The JumpThreadingCost map in Simplify CFG is used to prevent infinite jump threading loops. There was a missing update of the cost for blocks which are cloned: Jump threading loops were prevented for infinitely cloning the original block, but not for re-cloning the cloned block. A test case is already added in 8948f75 rdar://73357726, [SR-14068]
1 parent 4f5c75a commit fe928d5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@ bool SimplifyCFG::threadEdge(const ThreadInfo &ti) {
302302
return false;
303303

304304
Cloner.cloneBranchTarget(SrcTerm);
305+
JumpThreadingCost[Cloner.getNewBB()] = JumpThreadingCost[SrcTerm->getDestBB()];
306+
305307

306308
// We have copied the threaded block into the edge.
307309
auto *clonedSrc = Cloner.getNewBB();
@@ -1112,6 +1114,10 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
11121114
Cloner.cloneBranchTarget(BI);
11131115
Cloner.updateSSAAfterCloning();
11141116

1117+
// Also account the costs to the cloned DestBB, so the jump threading cannot
1118+
// loop by cloning the cloned block again.
1119+
JumpThreadingCost[Cloner.getNewBB()] += copyCosts;
1120+
11151121
// Once all the instructions are copied, we can nuke BI itself. We also add
11161122
// the threaded and edge block to the worklist now that they (likely) can be
11171123
// simplified.
@@ -2852,6 +2858,8 @@ bool SimplifyCFG::tailDuplicateObjCMethodCallSuccessorBlocks() {
28522858
Cloner.cloneBranchTarget(Branch);
28532859
Cloner.updateSSAAfterCloning();
28542860

2861+
JumpThreadingCost[Cloner.getNewBB()] = JumpThreadingCost[DestBB];
2862+
28552863
Changed = true;
28562864
// Simplify the cloned block and continue tail duplicating through its new
28572865
// successors edges.

0 commit comments

Comments
 (0)