Skip to content

Commit

Permalink
JIT: Avoid relying on bbNum to find lexical loop boundaries (dotnet#1…
Browse files Browse the repository at this point in the history
…01714)

Switch `FlowGraphNaturalLoop::GetLexicallyTopMostBlock` and
`FlowGraphNaturalLoop::GetLexicallyBottomMostBlock` to more robust
implementations that scan the basic block list forwards (and backwards)
to find the boundary blocks.

Fix dotnet#101695
  • Loading branch information
jakobbotsch authored and michaelgsharp committed May 8, 2024
1 parent bba287a commit d9e7f2a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5555,20 +5555,21 @@ bool FlowGraphNaturalLoop::InitBlockEntersLoopOnTrue(BasicBlock* initBlock)
// the loop.
//
// Returns:
// Block with highest bbNum.
// First block in block order contained in the loop.
//
// Remarks:
// Mostly exists as a quirk while transitioning from the old loop
// representation to the new one.
//
BasicBlock* FlowGraphNaturalLoop::GetLexicallyTopMostBlock()
{
BasicBlock* top = m_header;
VisitLoopBlocks([&top](BasicBlock* loopBlock) {
if (loopBlock->bbNum < top->bbNum)
top = loopBlock;
return BasicBlockVisit::Continue;
});
BasicBlock* top = m_dfsTree->GetCompiler()->fgFirstBB;

while (!ContainsBlock(top))
{
top = top->Next();
assert(top != nullptr);
}

return top;
}
Expand All @@ -5578,20 +5579,21 @@ BasicBlock* FlowGraphNaturalLoop::GetLexicallyTopMostBlock()
// within the loop.
//
// Returns:
// Block with highest bbNum.
// Last block in block order contained in the loop.
//
// Remarks:
// Mostly exists as a quirk while transitioning from the old loop
// representation to the new one.
//
BasicBlock* FlowGraphNaturalLoop::GetLexicallyBottomMostBlock()
{
BasicBlock* bottom = m_header;
VisitLoopBlocks([&bottom](BasicBlock* loopBlock) {
if (loopBlock->bbNum > bottom->bbNum)
bottom = loopBlock;
return BasicBlockVisit::Continue;
});
BasicBlock* bottom = m_dfsTree->GetCompiler()->fgLastBB;

while (!ContainsBlock(bottom))
{
bottom = bottom->Prev();
assert(bottom != nullptr);
}

return bottom;
}
Expand Down

0 comments on commit d9e7f2a

Please sign in to comment.