@@ -5246,13 +5246,6 @@ void Compiler::ThreeOptLayout::Run()
5246
5246
assert (finalBlock != nullptr );
5247
5247
assert (!finalBlock->isBBCallFinallyPair ());
5248
5248
5249
- // For methods with fewer than three candidate blocks, we cannot partition anything
5250
- if (finalBlock->IsFirst () || finalBlock->Prev ()->IsFirst ())
5251
- {
5252
- JITDUMP (" Not enough blocks to partition anything. Skipping 3-opt.\n " );
5253
- return ;
5254
- }
5255
-
5256
5249
// Get an upper bound on the number of hot blocks without walking the whole block list.
5257
5250
// We will only consider blocks reachable via normal flow.
5258
5251
const unsigned numBlocksUpperBound = compiler->m_dfsTree ->GetPostOrderCount ();
@@ -5269,13 +5262,20 @@ void Compiler::ThreeOptLayout::Run()
5269
5262
}
5270
5263
5271
5264
assert (numCandidateBlocks < numBlocksUpperBound);
5272
- blockOrder[numCandidateBlocks] = tempOrder[numCandidateBlocks] = block;
5265
+ blockOrder[numCandidateBlocks] = block;
5273
5266
5274
5267
// Repurpose 'bbPostorderNum' for the block's ordinal
5275
5268
block->bbPostorderNum = numCandidateBlocks++;
5276
5269
}
5277
5270
5278
- const bool modified = RunThreeOptPass ();
5271
+ // For methods with fewer than three candidate blocks, we cannot partition anything
5272
+ if (numCandidateBlocks < 3 )
5273
+ {
5274
+ JITDUMP (" Not enough blocks to partition anything. Skipping reordering.\n " );
5275
+ return ;
5276
+ }
5277
+
5278
+ const bool modified = RunThreeOpt ();
5279
5279
5280
5280
if (modified)
5281
5281
{
@@ -5504,31 +5504,23 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
5504
5504
}
5505
5505
5506
5506
// -----------------------------------------------------------------------------
5507
- // Compiler::ThreeOptLayout::RunThreeOptPass : Runs 3-opt on the candidate span of blocks.
5507
+ // Compiler::ThreeOptLayout::RunThreeOpt : Runs 3-opt on the candidate span of blocks.
5508
5508
//
5509
5509
// Returns:
5510
5510
// True if we reordered anything, false otherwise
5511
5511
//
5512
- bool Compiler::ThreeOptLayout::RunThreeOptPass ()
5512
+ bool Compiler::ThreeOptLayout::RunThreeOpt ()
5513
5513
{
5514
- const unsigned startPos = 0 ;
5515
- const unsigned endPos = numCandidateBlocks - 1 ;
5516
- const unsigned numBlocks = (endPos - startPos + 1 );
5517
- assert (startPos <= endPos);
5518
-
5519
- if (numBlocks < 3 )
5520
- {
5521
- JITDUMP (" Not enough blocks to partition anything. Skipping reordering.\n " );
5522
- return false ;
5523
- }
5514
+ // We better have enough blocks to create partitions
5515
+ assert (numCandidateBlocks > 2 );
5516
+ const unsigned startPos = 0 ;
5517
+ const unsigned endPos = numCandidateBlocks - 1 ;
5524
5518
5525
5519
JITDUMP (" Initial layout cost: %f\n " , GetLayoutCost (startPos, endPos));
5526
5520
const bool modified = RunGreedyThreeOptPass (startPos, endPos);
5527
5521
5528
- // Write back to 'tempOrder' so changes to this region aren't lost next time we swap 'tempOrder' and 'blockOrder'
5529
5522
if (modified)
5530
5523
{
5531
- memcpy (tempOrder + startPos, blockOrder + startPos, sizeof (BasicBlock*) * numBlocks);
5532
5524
JITDUMP (" Final layout cost: %f\n " , GetLayoutCost (startPos, endPos));
5533
5525
}
5534
5526
else
0 commit comments