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

[release/6.0] JIT: fix scalability issue in redundant branch optimizer #68972

Merged
merged 1 commit into from
May 14, 2022
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
18 changes: 15 additions & 3 deletions src/coreclr/jit/redundantbranchopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ bool Compiler::optRedundantBranch(BasicBlock* const block)
// Walk up the dom tree and see if any dominating block has branched on
// exactly this tree's VN...
//
BasicBlock* prevBlock = block;
BasicBlock* domBlock = block->bbIDom;
int relopValue = -1;
BasicBlock* prevBlock = block;
BasicBlock* domBlock = block->bbIDom;
int relopValue = -1;
unsigned matchCount = 0;
const unsigned matchLimit = 4;

if (domBlock == nullptr)
{
Expand Down Expand Up @@ -140,6 +142,16 @@ bool Compiler::optRedundantBranch(BasicBlock* const block)
//
if (domCmpVN == tree->GetVN(VNK_Liberal))
{
// If we have a long skinny dominator tree we may scale poorly,
// and in particular reachability (below) is costly. Give up if
// we've matched a few times and failed to optimize.
//
if (++matchCount > matchLimit)
{
JITDUMP("Bailing out; %d matches found w/o optimizing\n", matchCount);
return false;
}

// The compare in "tree" is redundant.
// Is there a unique path from the dominating compare?
//
Expand Down