diff --git a/src/coreclr/jit/block.cpp b/src/coreclr/jit/block.cpp index 2ecf31eb23c7b7..ad68ca14454c6e 100644 --- a/src/coreclr/jit/block.cpp +++ b/src/coreclr/jit/block.cpp @@ -424,7 +424,7 @@ bool BasicBlock::IsFirstColdBlock(Compiler* compiler) const bool BasicBlock::CanRemoveJumpToNext(Compiler* compiler) const { assert(KindIs(BBJ_ALWAYS)); - return JumpsToNext() && (bbNext != compiler->fgFirstColdBlock); + return JumpsToNext() && !IsLastHotBlock(compiler); } //------------------------------------------------------------------------ @@ -441,7 +441,7 @@ bool BasicBlock::CanRemoveJumpToTarget(BasicBlock* target, Compiler* compiler) c { assert(KindIs(BBJ_COND)); assert(TrueTargetIs(target) || FalseTargetIs(target)); - return NextIs(target) && !compiler->fgInDifferentRegions(this, target); + return NextIs(target) && !IsLastHotBlock(compiler); } #ifdef DEBUG diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index d27fc704eca583..30a3a83581a3bb 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -4945,7 +4945,7 @@ BasicBlock* Compiler::fgSplitEdge(BasicBlock* curr, BasicBlock* succ) // Removes the block from the bbPrev/bbNext chain // Updates fgFirstBB and fgLastBB if necessary -// Does not update fgFirstFuncletBB or fgFirstColdBlock (fgUnlinkRange does) +// Does not update fgFirstFuncletBB void Compiler::fgUnlinkBlock(BasicBlock* block) { if (block->IsFirst()) @@ -5006,6 +5006,9 @@ void Compiler::fgUnlinkRange(BasicBlock* bBeg, BasicBlock* bEnd) assert(bBeg != nullptr); assert(bEnd != nullptr); + // We shouldn't be churning the flowgraph after doing hot/cold splitting + assert(fgFirstColdBlock == nullptr); + BasicBlock* bPrev = bBeg->Prev(); assert(bPrev != nullptr); // Can't unlink a range starting with the first block @@ -5020,12 +5023,6 @@ void Compiler::fgUnlinkRange(BasicBlock* bBeg, BasicBlock* bEnd) bPrev->SetNext(bEnd->Next()); } - // If bEnd was the first Cold basic block update fgFirstColdBlock - if (bEnd->IsFirstColdBlock(this)) - { - fgFirstColdBlock = bPrev->Next(); - } - #ifdef DEBUG if (UsesFunclets()) { @@ -5056,6 +5053,9 @@ BasicBlock* Compiler::fgRemoveBlock(BasicBlock* block, bool unreachable) { assert(block != nullptr); + // We shouldn't churn the flowgraph after doing hot/cold splitting + assert(fgFirstColdBlock == nullptr); + JITDUMP("fgRemoveBlock " FMT_BB ", unreachable=%s\n", block->bbNum, dspBool(unreachable)); BasicBlock* bPrev = block->Prev(); @@ -5079,12 +5079,6 @@ BasicBlock* Compiler::fgRemoveBlock(BasicBlock* block, bool unreachable) fgFirstFuncletBB = block->Next(); } - // If this is the first Cold basic block update fgFirstColdBlock - if (block->IsFirstColdBlock(this)) - { - fgFirstColdBlock = block->Next(); - } - // A BBJ_CALLFINALLY is usually paired with a BBJ_CALLFINALLYRET. // If we delete such a BBJ_CALLFINALLY we also delete the BBJ_CALLFINALLYRET. if (block->isBBCallFinallyPair()) @@ -5141,12 +5135,6 @@ BasicBlock* Compiler::fgRemoveBlock(BasicBlock* block, bool unreachable) skipUnmarkLoop = true; } - // If this is the first Cold basic block update fgFirstColdBlock - if (block->IsFirstColdBlock(this)) - { - fgFirstColdBlock = block->Next(); - } - // Update fgFirstFuncletBB if necessary if (block == fgFirstFuncletBB) { diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index a54f36298ac3eb..a0cc88a2be63f0 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -830,13 +830,6 @@ bool Compiler::fgCanCompactBlock(BasicBlock* block) return false; } - // We don't want to compact blocks that are in different hot/cold regions - // - if (fgInDifferentRegions(block, target)) - { - return false; - } - // We cannot compact two blocks in different EH regions. // if (!BasicBlock::sameEHRegion(block, target)) @@ -872,6 +865,10 @@ bool Compiler::fgCanCompactBlock(BasicBlock* block) void Compiler::fgCompactBlock(BasicBlock* block) { assert(fgCanCompactBlock(block)); + + // We shouldn't churn the flowgraph after doing hot/cold splitting + assert(fgFirstColdBlock == nullptr); + BasicBlock* const target = block->GetTarget(); JITDUMP("\nCompacting " FMT_BB " into " FMT_BB ":\n", target->bbNum, block->bbNum); @@ -1356,6 +1353,9 @@ bool Compiler::fgOptimizeEmptyBlock(BasicBlock* block) { assert(block->isEmpty()); + // We shouldn't churn the flowgraph after doing hot/cold splitting + assert(fgFirstColdBlock == nullptr); + bool madeChanges = false; BasicBlock* bPrev = block->Prev(); @@ -1401,12 +1401,6 @@ bool Compiler::fgOptimizeEmptyBlock(BasicBlock* block) break; } - // can't allow fall through into cold code - if (block->IsLastHotBlock(this)) - { - break; - } - // Don't remove fgEntryBB if (block == fgEntryBB) { @@ -5610,6 +5604,9 @@ bool Compiler::fgUpdateFlowGraph(bool doTailDuplication /* = false */, noway_assert(opts.OptimizationEnabled()); + // We shouldn't be churning the flowgraph after doing hot/cold splitting + assert(fgFirstColdBlock == nullptr); + #ifdef DEBUG if (verbose && !isPhase) { @@ -5766,9 +5763,7 @@ bool Compiler::fgUpdateFlowGraph(bool doTailDuplication /* = false */, bNext->KindIs(BBJ_ALWAYS) && // the next block is a BBJ_ALWAYS block !bNext->JumpsToNext() && // and it doesn't jump to the next block (we might compact them) bNext->isEmpty() && // and it is an empty block - !bNext->TargetIs(bNext) && // special case for self jumps - !bDest->IsFirstColdBlock(this) && - !fgInDifferentRegions(block, bDest)) // do not cross hot/cold sections + !bNext->TargetIs(bNext)) // special case for self jumps { assert(block->FalseTargetIs(bNext)); @@ -5812,20 +5807,6 @@ bool Compiler::fgUpdateFlowGraph(bool doTailDuplication /* = false */, optimizeJump = false; } - // If we are optimizing using real profile weights - // then don't optimize a conditional jump to an unconditional jump - // until after we have computed the edge weights - // - if (fgIsUsingProfileWeights()) - { - // if block and bDest are in different hot/cold regions we can't do this optimization - // because we can't allow fall-through into the cold region. - if (fgInDifferentRegions(block, bDest)) - { - optimizeJump = false; - } - } - if (optimizeJump && isJumpToJoinFree) { // In the join free case, we also need to move bDest right after bNext @@ -5914,12 +5895,6 @@ bool Compiler::fgUpdateFlowGraph(bool doTailDuplication /* = false */, /* Mark the block as removed */ bNext->SetFlags(BBF_REMOVED); - // If this is the first Cold basic block update fgFirstColdBlock - if (bNext->IsFirstColdBlock(this)) - { - fgFirstColdBlock = bNext->Next(); - } - // // If we removed the end of a try region or handler region // we will need to update ebdTryLast or ebdHndLast.