Skip to content
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

[DNM] Disable jump threading through a potential loop header #76305

Closed
Closed
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
20 changes: 8 additions & 12 deletions lib/SILOptimizer/Transforms/SimplifyCFG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,14 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
// currently handle).
if (BI->getArgs().empty() && !isa<SwitchEnumAddrInst>(destTerminator))
return false;


// Don't jump thread through a potential header - this can produce irreducible
// control flow and lead to infinite loop peeling.
bool DestIsLoopHeader = (LoopHeaders.count(DestBB) != 0);
if (DestIsLoopHeader) {
return false;
}

// We don't have a great cost model at the SIL level, so we don't want to
// blissly duplicate tons of code with a goal of improved performance (we'll
// leave that to LLVM). However, doing limited code duplication can lead to
Expand Down Expand Up @@ -1011,17 +1018,6 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
if (ThreadingBudget <= 0)
return false;

// Don't jump thread through a potential header - this can produce irreducible
// control flow and lead to infinite loop peeling.
bool DestIsLoopHeader = (LoopHeaders.count(DestBB) != 0);
if (DestIsLoopHeader) {
// Make an exception for switch_enum, but only if it's block was not already
// peeled out of it's original loop. In that case, further jump threading
// can accomplish nothing, and the loop will be infinitely peeled.
if (!isa<SwitchEnumInst>(destTerminator) || ClonedLoopHeaders.count(DestBB))
return false;
}

// If it looks potentially interesting, decide whether we *can* do the
// operation and whether the block is small enough to be worth duplicating.
int copyCosts = 0;
Expand Down