Skip to content

SimplifyCFG: fix an infinite jump-threading loop. #35614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/SILOptimizer/Transforms/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ bool SimplifyCFG::threadEdge(const ThreadInfo &ti) {
return false;

Cloner.cloneBranchTarget(SrcTerm);
JumpThreadingCost[Cloner.getNewBB()] = JumpThreadingCost[SrcTerm->getDestBB()];


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

// Also account the costs to the cloned DestBB, so the jump threading cannot
// loop by cloning the cloned block again.
JumpThreadingCost[Cloner.getNewBB()] += copyCosts;

// Once all the instructions are copied, we can nuke BI itself. We also add
// the threaded and edge block to the worklist now that they (likely) can be
// simplified.
Expand Down Expand Up @@ -2852,6 +2858,8 @@ bool SimplifyCFG::tailDuplicateObjCMethodCallSuccessorBlocks() {
Cloner.cloneBranchTarget(Branch);
Cloner.updateSSAAfterCloning();

JumpThreadingCost[Cloner.getNewBB()] = JumpThreadingCost[DestBB];

Changed = true;
// Simplify the cloned block and continue tail duplicating through its new
// successors edges.
Expand Down