Skip to content

Commit

Permalink
JIT: improve scalability of optReachable
Browse files Browse the repository at this point in the history
Use a bit vector to track the visited blocks. This scales much better than
using the per-block visited flags.

Fixes dotnet#44341.
  • Loading branch information
AndyAyersMS committed Sep 21, 2022
1 parent 77bf509 commit 7d4dc9f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6980,6 +6980,8 @@ class Compiler
bool optRedundantBranch(BasicBlock* const block);
bool optJumpThread(BasicBlock* const block, BasicBlock* const domBlock, bool domIsSameRelop);
bool optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlock, BasicBlock* const excludedBlock);
BitVecTraits* optReachableBitVecTraits;
BitVec optReachableBitVec;
void optRelopImpliesRelop(RelopImplicationInfo* rii);

/**************************************************************************
Expand Down
23 changes: 12 additions & 11 deletions src/coreclr/jit/redundantbranchopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,10 @@ PhaseStatus Compiler::optRedundantBranches()
}
};

optReachableBitVecTraits = nullptr;
OptRedundantBranchesDomTreeVisitor visitor(this);
visitor.WalkTree();

// Reset visited flags, in case we set any.
//
for (BasicBlock* const block : Blocks())
{
block->bbFlags &= ~BBF_VISITED;
}

#if DEBUG
if (verbose && visitor.madeChanges)
{
Expand Down Expand Up @@ -1593,9 +1587,15 @@ bool Compiler::optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlo
return true;
}

for (BasicBlock* const block : Blocks())
if (optReachableBitVecTraits == nullptr)
{
block->bbFlags &= ~BBF_VISITED;
optReachableBitVecTraits = new (this, CMK_Reachability) BitVecTraits(fgBBNumMax + 1, this);
optReachableBitVec = BitVecOps::MakeEmpty(optReachableBitVecTraits);
}
else
{
assert(BitVecTraits::GetSize(optReachableBitVecTraits) == fgBBNumMax + 1);
BitVecOps::ClearD(optReachableBitVecTraits, optReachableBitVec);
}

ArrayStack<BasicBlock*> stack(getAllocator(CMK_Reachability));
Expand All @@ -1604,7 +1604,6 @@ bool Compiler::optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlo
while (!stack.Empty())
{
BasicBlock* const nextBlock = stack.Pop();
nextBlock->bbFlags |= BBF_VISITED;
assert(nextBlock != toBlock);

if (nextBlock == excludedBlock)
Expand All @@ -1619,11 +1618,13 @@ bool Compiler::optReachable(BasicBlock* const fromBlock, BasicBlock* const toBlo
return true;
}

if ((succ->bbFlags & BBF_VISITED) != 0)
if (BitVecOps::IsMember(optReachableBitVecTraits, optReachableBitVec, succ->bbNum))
{
continue;
}

BitVecOps::AddElemD(optReachableBitVecTraits, optReachableBitVec, succ->bbNum);

stack.Push(succ);
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
<ExcludeList Include="$(XunitTestBinBase)/readytorun/r2rdump/BasicTests/R2RDumpTest/*">
<Issue>https://github.com/dotnet/runtime/issues/10888 https://github.com/dotnet/runtime/issues/11823 </Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Regression/JitBlue/DevDiv_255294/DevDiv_255294/*">
<Issue>https://github.com/dotnet/runtime/issues/44341</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/JIT/Directed/rvastatics/RVAOrderingTest/*">
<Issue>https://github.com/dotnet/runtime/issues/55966</Issue>
</ExcludeList>
Expand Down

0 comments on commit 7d4dc9f

Please sign in to comment.