@@ -5236,11 +5236,12 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
52365236 m_pLowering->FinalizeOutgoingArgSpace ();
52375237
52385238 // We can not add any new tracked variables after this point.
5239- lvaTrackedFixed = true ;
5239+ lvaTrackedFixed = true ;
5240+ const unsigned numBlocksBeforeLSRA = fgBBcount;
52405241
52415242 // Now that lowering is completed we can proceed to perform register allocation
52425243 //
5243- auto linearScanPhase = [this ]() {
5244+ auto linearScanPhase = [this ] {
52445245 m_pLinearScan->doLinearScan ();
52455246 };
52465247 DoPhase (this , PHASE_LINEAR_SCAN, linearScanPhase);
@@ -5250,8 +5251,25 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
52505251
52515252 if (opts.OptimizationEnabled ())
52525253 {
5253- // LSRA and stack level setting can modify the flowgraph.
5254- // Now that it won't change, run post-layout optimizations.
5254+ // LSRA may introduce new blocks. If it does, rerun layout.
5255+ if ((fgBBcount != numBlocksBeforeLSRA) && JitConfig.JitDoReversePostOrderLayout ())
5256+ {
5257+ auto lateLayoutPhase = [this ] {
5258+ fgDoReversePostOrderLayout ();
5259+ fgMoveColdBlocks ();
5260+ return PhaseStatus::MODIFIED_EVERYTHING;
5261+ };
5262+
5263+ DoPhase (this , PHASE_OPTIMIZE_LAYOUT, lateLayoutPhase);
5264+
5265+ if (fgFirstColdBlock != nullptr )
5266+ {
5267+ fgFirstColdBlock = nullptr ;
5268+ DoPhase (this , PHASE_DETERMINE_FIRST_COLD_BLOCK, &Compiler::fgDetermineFirstColdBlock);
5269+ }
5270+ }
5271+
5272+ // Now that the flowgraph is finalized, run post-layout optimizations.
52555273 DoPhase (this , PHASE_OPTIMIZE_POST_LAYOUT, &Compiler::optOptimizePostLayout);
52565274 }
52575275
0 commit comments