Skip to content

Commit 04be7a9

Browse files
authored
JIT: fix scalability issue in redundant branch optimizer (#66259)
In methods with long skinny dominator trees and lots of redundant branches the jit can spend too much time trying to optimize the branches. Place a limit on the number of redundant branches with matching VNs that the jit will consider for a given branch. Fixes #66067.
1 parent f9da3db commit 04be7a9

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/coreclr/jit/redundantbranchopts.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,11 @@ bool Compiler::optRedundantBranch(BasicBlock* const block)
107107
// Walk up the dom tree and see if any dominating block has branched on
108108
// exactly this tree's VN...
109109
//
110-
BasicBlock* prevBlock = block;
111-
BasicBlock* domBlock = block->bbIDom;
112-
int relopValue = -1;
110+
BasicBlock* prevBlock = block;
111+
BasicBlock* domBlock = block->bbIDom;
112+
int relopValue = -1;
113+
unsigned matchCount = 0;
114+
const unsigned matchLimit = 4;
113115

114116
if (domBlock == nullptr)
115117
{
@@ -164,6 +166,16 @@ bool Compiler::optRedundantBranch(BasicBlock* const block)
164166
//
165167
if (matched)
166168
{
169+
// If we have a long skinny dominator tree we may scale poorly,
170+
// and in particular reachability (below) is costly. Give up if
171+
// we've matched a few times and failed to optimize.
172+
//
173+
if (++matchCount > matchLimit)
174+
{
175+
JITDUMP("Bailing out; %d matches found w/o optimizing\n", matchCount);
176+
return false;
177+
}
178+
167179
// The compare in "tree" is redundant.
168180
// Is there a unique path from the dominating compare?
169181
//

0 commit comments

Comments
 (0)