diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 5b451505a6ec2..ee283567b5566 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -4325,6 +4325,7 @@ class Compiler unsigned fgBBcountAtCodegen; // # of BBs in the method at the start of codegen jitstd::vector* 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 diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index 294a92ab8020f..e716142c76d04 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -64,6 +64,7 @@ void Compiler::fgInit() fgBBOrder = nullptr; #endif // DEBUG + fgBBNumMin = compIsForInlining() ? impInlineRoot()->fgBBNumMax + 1 : 1; fgBBNumMax = 0; fgEdgeCount = 0; fgDomBBcount = 0; @@ -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. diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index c16730d655a20..5adf6e1378840 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -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) @@ -5518,8 +5519,7 @@ 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++) @@ -5527,7 +5527,16 @@ void Compiler::fgMorphCallInlineHelper(GenTreeCall* call, InlineResult* result, 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 } }