// 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)
{
//
if (matched)
{
+ // 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?
//