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

Fix loop cloning for OSR #67067

Merged
merged 1 commit into from
Mar 24, 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
5 changes: 3 additions & 2 deletions src/coreclr/jit/loopcloning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1904,13 +1904,14 @@ void Compiler::optCloneLoop(unsigned loopInd, LoopCloneContext* context)
// so that "h" already falls through to "e" (e == t).
// It might look like this code is unreachable, since "h" must be a BBJ_ALWAYS, but
// later we will change "h" to a BBJ_COND along with a set of loop conditions.
// TODO: it still might be unreachable, since cloning currently is restricted to "do-while" loop forms.
// Cloning is currently restricted to "do-while" loop forms, where this case won't occur.
// However, it can occur in OSR methods.
BasicBlock* h2 = nullptr;
if (h->bbNext != loop.lpEntry)
{
assert(h->bbJumpKind == BBJ_ALWAYS);
JITDUMP("Create branch to entry of optimized loop\n");
BasicBlock* h2 = fgNewBBafter(BBJ_ALWAYS, h, /*extendRegion*/ true);
h2 = fgNewBBafter(BBJ_ALWAYS, h, /*extendRegion*/ true);
JITDUMP("Adding " FMT_BB " after " FMT_BB "\n", h2->bbNum, h->bbNum);
h2->bbWeight = h2->isRunRarely() ? BB_ZERO_WEIGHT : ambientWeight;

Expand Down
15 changes: 13 additions & 2 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3023,12 +3023,23 @@ bool Compiler::optLoopContains(unsigned l1, unsigned l2) const
}
}

//-----------------------------------------------------------------------------
// optUpdateLoopHead: Replace the `head` block of a loop in the loop table.
// Considers all child loops that might share the same head (recursively).
//
// Arguments:
// loopInd -- loop num of loop
// from -- current loop head block
// to -- replacement loop head block
//
void Compiler::optUpdateLoopHead(unsigned loopInd, BasicBlock* from, BasicBlock* to)
{
assert(optLoopTable[loopInd].lpHead == from);
JITDUMP("Replace " FMT_LP " head " FMT_BB " with " FMT_BB "\n", loopInd, from->bbNum, to->bbNum);
optLoopTable[loopInd].lpHead = to;
for (unsigned char childLoop = optLoopTable[loopInd].lpChild; childLoop != BasicBlock::NOT_IN_LOOP;
childLoop = optLoopTable[childLoop].lpSibling)
for (unsigned char childLoop = optLoopTable[loopInd].lpChild; //
childLoop != BasicBlock::NOT_IN_LOOP; //
childLoop = optLoopTable[childLoop].lpSibling)
{
if (optLoopTable[childLoop].lpHead == from)
{
Expand Down