@@ -5236,11 +5236,12 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
5236
5236
m_pLowering->FinalizeOutgoingArgSpace ();
5237
5237
5238
5238
// We can not add any new tracked variables after this point.
5239
- lvaTrackedFixed = true ;
5239
+ lvaTrackedFixed = true ;
5240
+ const unsigned numBlocksBeforeLSRA = fgBBcount;
5240
5241
5241
5242
// Now that lowering is completed we can proceed to perform register allocation
5242
5243
//
5243
- auto linearScanPhase = [this ]() {
5244
+ auto linearScanPhase = [this ] {
5244
5245
m_pLinearScan->doLinearScan ();
5245
5246
};
5246
5247
DoPhase (this , PHASE_LINEAR_SCAN, linearScanPhase);
@@ -5250,8 +5251,25 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
5250
5251
5251
5252
if (opts.OptimizationEnabled ())
5252
5253
{
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.
5255
5273
DoPhase (this , PHASE_OPTIMIZE_POST_LAYOUT, &Compiler::optOptimizePostLayout);
5256
5274
}
5257
5275
0 commit comments