Skip to content

Commit

Permalink
JIT: Remove fgRenumberBlocks calls in loop opt phases (dotnet#110227)
Browse files Browse the repository at this point in the history
Follow-up to dotnet#110026. This required a small refactor of FlowGraphNaturalLoop::VisitLoopBlocksLexical to remove its bbNum checks.
  • Loading branch information
amanasifkhalid authored and mikelle-rogers committed Dec 4, 2024
1 parent 87b6a93 commit b0bcb45
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 29 deletions.
33 changes: 7 additions & 26 deletions src/coreclr/jit/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5145,37 +5145,18 @@ BasicBlockVisit FlowGraphNaturalLoop::VisitLoopBlocks(TFunc func)
template <typename TFunc>
BasicBlockVisit FlowGraphNaturalLoop::VisitLoopBlocksLexical(TFunc func)
{
BasicBlock* top = m_header;
unsigned numLoopBlocks = 0;
VisitLoopBlocks([&](BasicBlock* block) {
if (block->bbNum < top->bbNum)
{
top = block;
}

numLoopBlocks++;
return BasicBlockVisit::Continue;
});
BasicBlock* const top = GetLexicallyTopMostBlock();
BasicBlock* const bottom = GetLexicallyBottomMostBlock();

INDEBUG(BasicBlock* prev = nullptr);
BasicBlock* cur = top;
while (numLoopBlocks > 0)
for (BasicBlock* const block : m_dfsTree->GetCompiler()->Blocks(top, bottom))
{
// If we run out of blocks the blocks aren't sequential.
assert(cur != nullptr);

if (ContainsBlock(cur))
if (ContainsBlock(block))
{
assert((prev == nullptr) || (prev->bbNum < cur->bbNum));

if (func(cur) == BasicBlockVisit::Abort)
if (func(block) == BasicBlockVisit::Abort)
{
return BasicBlockVisit::Abort;

INDEBUG(prev = cur);
numLoopBlocks--;
}
}

cur = cur->Next();
}

return BasicBlockVisit::Continue;
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/jit/loopcloning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3064,8 +3064,6 @@ PhaseStatus Compiler::optCloneLoops()
m_dfsTree = fgComputeDfs();
m_loops = FlowGraphNaturalLoops::Find(m_dfsTree);
}

fgRenumberBlocks();
}

#ifdef DEBUG
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,6 @@ PhaseStatus Compiler::optUnrollLoops()
}

JITDUMP("A nested loop was unrolled. Doing another pass (pass %d)\n", passes + 1);
fgRenumberBlocks();
fgInvalidateDfsTree();
m_dfsTree = fgComputeDfs();
m_loops = FlowGraphNaturalLoops::Find(m_dfsTree);
Expand Down

0 comments on commit b0bcb45

Please sign in to comment.