Skip to content

JIT: improve scalability of optReachable #75990

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

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
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
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this exact code in fgRemoveDeadBlocks(). Can we unify them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That version uses BlockSet, which I'm avoiding here because it is epoch sensitive.

In general, it would be nice to have the ability to represent (sparse) block sets that are independent of bbNum and not fixed capacity so that they can persist for longer stretches or be reused as general scratch sets, but we don't have anything like that yet.

{
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