Skip to content
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

[release/6.0] JIT: Abandon loop search if we reach the end of the bbNext chain #69525

Merged
merged 1 commit into from
Jun 9, 2022
Merged
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
17 changes: 15 additions & 2 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1928,13 +1928,26 @@ class LoopSearch
// This blocks is lexically between TOP and BOTTOM, but it does not
// participate in the flow cycle. Check for a run of consecutive
// such blocks.
//
// If blocks have been reordered and bbNum no longer reflects bbNext ordering
// (say by a call to MakeCompactAndFindExits for an earlier loop or unsuccessful
// attempt to find a loop), the bottom block of this loop may now appear earlier
// in the bbNext chain than other loop blocks. So when the previous hasn't reached bottom
// and block is a non-loop block, and we walk the bbNext chain, we may reach the end.
// If so, give up on recognition of this loop.
//
BasicBlock* lastNonLoopBlock = block;
BasicBlock* nextLoopBlock = block->bbNext;
while (!loopBlocks.IsMember(nextLoopBlock->bbNum))
while ((nextLoopBlock != nullptr) && !loopBlocks.IsMember(nextLoopBlock->bbNum))
{
lastNonLoopBlock = nextLoopBlock;
nextLoopBlock = nextLoopBlock->bbNext;
// This loop must terminate because we know BOTTOM is in loopBlocks.
}

if (nextLoopBlock == nullptr)
{
JITDUMP("Did not find expected loop block when walking from " FMT_BB "\n", lastNonLoopBlock->bbNum);
return false;
}

// Choose an insertion point for non-loop blocks if we haven't yet done so.
Expand Down