diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 4aeb1805c41b6..27ed0df9a5423 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -5235,8 +5235,7 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl m_pLowering->FinalizeOutgoingArgSpace(); // We can not add any new tracked variables after this point. - lvaTrackedFixed = true; - const unsigned numBlocksBeforeLSRA = fgBBcount; + lvaTrackedFixed = true; // Now that lowering is completed we can proceed to perform register allocation // @@ -5250,8 +5249,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl if (opts.OptimizationEnabled()) { - // LSRA may introduce new blocks. If it does, rerun layout. - if ((fgBBcount != numBlocksBeforeLSRA) && JitConfig.JitDoReversePostOrderLayout()) + // We won't introduce new blocks from here on out, + // so run the new block layout. + // + if (JitConfig.JitDoReversePostOrderLayout()) { auto lateLayoutPhase = [this] { fgDoReversePostOrderLayout(); @@ -5272,7 +5273,12 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl DoPhase(this, PHASE_DETERMINE_FIRST_COLD_BLOCK, &Compiler::fgDetermineFirstColdBlock); // Now that the flowgraph is finalized, run post-layout optimizations. + // DoPhase(this, PHASE_OPTIMIZE_POST_LAYOUT, &Compiler::optOptimizePostLayout); + + // Determine start of cold region if we are hot/cold splitting + // + DoPhase(this, PHASE_DETERMINE_FIRST_COLD_BLOCK, &Compiler::fgDetermineFirstColdBlock); } #if FEATURE_LOOP_ALIGN diff --git a/src/coreclr/jit/fgopt.cpp b/src/coreclr/jit/fgopt.cpp index 45bdd67a99781..742f58364a390 100644 --- a/src/coreclr/jit/fgopt.cpp +++ b/src/coreclr/jit/fgopt.cpp @@ -3341,22 +3341,12 @@ bool Compiler::fgReorderBlocks(bool useProfile) if (useProfile) { + // Don't run the new layout until we get to the backend, + // since LSRA can introduce new blocks, and lowering can churn the flowgraph. + // if (JitConfig.JitDoReversePostOrderLayout()) { - fgDoReversePostOrderLayout(); - fgMoveColdBlocks(); - - if (compHndBBtabCount != 0) - { - fgRebuildEHRegions(); - } - - // Renumber blocks to facilitate LSRA's order of block visitation - // TODO: Consider removing this, and using traversal order in lSRA - // - fgRenumberBlocks(); - - return true; + return (newRarelyRun || movedBlocks || optimizedSwitches); } // We will be reordering blocks, so ensure the false target of a BBJ_COND block is its next block