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

JIT: reset max bbnum after failed inline attempt #80958

Merged
merged 2 commits into from
Jan 22, 2023
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
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4325,6 +4325,7 @@ class Compiler
unsigned fgBBcountAtCodegen; // # of BBs in the method at the start of codegen
jitstd::vector<BasicBlock*>* fgBBOrder; // ordered vector of BBs
#endif
unsigned fgBBNumMin; // The min bbNum that has been assigned to basic blocks
unsigned fgBBNumMax; // The max bbNum that has been assigned to basic blocks
unsigned fgDomBBcount; // # of BBs for which we have dominator and reachability information
BasicBlock** fgBBInvPostOrder; // The flow graph stored in an array sorted in topological order, needed to compute
Expand Down
42 changes: 13 additions & 29 deletions src/coreclr/jit/fgbasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void Compiler::fgInit()
fgBBOrder = nullptr;
#endif // DEBUG

fgBBNumMin = compIsForInlining() ? impInlineRoot()->fgBBNumMax + 1 : 1;
fgBBNumMax = 0;
fgEdgeCount = 0;
fgDomBBcount = 0;
Expand Down Expand Up @@ -5352,50 +5353,33 @@ bool Compiler::fgRenumberBlocks()
}
#endif // DEBUG

bool renumbered = false;
bool newMaxBBNum = false;
BasicBlock* block;

unsigned numStart = 1 + (compIsForInlining() ? impInlineInfo->InlinerCompiler->fgBBNumMax : 0);
unsigned num;
bool renumbered = false;
bool newMaxBBNum = false;
unsigned num = fgBBNumMin;

for (block = fgFirstBB, num = numStart; block != nullptr; block = block->bbNext, num++)
for (BasicBlock* block : Blocks())
{
noway_assert((block->bbFlags & BBF_REMOVED) == 0);

if (block->bbNum != num)
{
renumbered = true;
#ifdef DEBUG
if (verbose)
{
printf("Renumber " FMT_BB " to " FMT_BB "\n", block->bbNum, num);
}
#endif // DEBUG
JITDUMP("Renumber " FMT_BB " to " FMT_BB "\n", block->bbNum, num);
renumbered = true;
block->bbNum = num;
}

if (block->bbNext == nullptr)
{
fgLastBB = block;
fgBBcount = num - numStart + 1;
if (compIsForInlining())
fgBBcount = num - fgBBNumMin + 1;
if (fgBBNumMax != num)
{
if (impInlineInfo->InlinerCompiler->fgBBNumMax != num)
{
impInlineInfo->InlinerCompiler->fgBBNumMax = num;
newMaxBBNum = true;
}
}
else
{
if (fgBBNumMax != num)
{
fgBBNumMax = num;
newMaxBBNum = true;
}
fgBBNumMax = num;
newMaxBBNum = true;
}
}

num++;
}

// If we renumbered, then we may need to reorder some pred lists.
Expand Down
17 changes: 13 additions & 4 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5492,7 +5492,8 @@ void Compiler::fgMorphCallInlineHelper(GenTreeCall* call, InlineResult* result,
// Calling inlinee's compiler to inline the method.
//

unsigned startVars = lvaCount;
unsigned const startVars = lvaCount;
unsigned const startBBNumMax = fgBBNumMax;

#ifdef DEBUG
if (verbose)
Expand All @@ -5518,16 +5519,24 @@ void Compiler::fgMorphCallInlineHelper(GenTreeCall* call, InlineResult* result,

if (result->IsFailure())
{
// Undo some changes made in anticipation of inlining...

// Undo some changes made during the inlining attempt.
// Zero out the used locals
memset((void*)(lvaTable + startVars), 0, (lvaCount - startVars) * sizeof(*lvaTable));
for (unsigned i = startVars; i < lvaCount; i++)
{
new (&lvaTable[i], jitstd::placement_t()) LclVarDsc(); // call the constructor.
}

lvaCount = startVars;
// Reset local var count and max bb num
lvaCount = startVars;
fgBBNumMax = startBBNumMax;

#ifdef DEBUG
for (BasicBlock* block : Blocks())
{
assert(block->bbNum <= fgBBNumMax);
}
#endif
}
}

Expand Down