Skip to content

Commit 73efdf3

Browse files
JIT: Clean up 3-opt driver logic (#112210)
Follow-up to #111989. Now that we only run one pass of 3-opt, we can remove some cruft needed to maintain state across 3-opt passes. This is a meek attempt to reduce the size of #112004 by separating out some of the no-diff changes.
1 parent 666bb9d commit 73efdf3

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

src/coreclr/jit/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6377,7 +6377,7 @@ class Compiler
63776377
void AddNonFallthroughPreds(unsigned blockPos);
63786378
bool RunGreedyThreeOptPass(unsigned startPos, unsigned endPos);
63796379

6380-
bool RunThreeOptPass();
6380+
bool RunThreeOpt();
63816381

63826382
public:
63836383
ThreeOptLayout(Compiler* comp);

src/coreclr/jit/fgopt.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5246,13 +5246,6 @@ void Compiler::ThreeOptLayout::Run()
52465246
assert(finalBlock != nullptr);
52475247
assert(!finalBlock->isBBCallFinallyPair());
52485248

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-
52565249
// Get an upper bound on the number of hot blocks without walking the whole block list.
52575250
// We will only consider blocks reachable via normal flow.
52585251
const unsigned numBlocksUpperBound = compiler->m_dfsTree->GetPostOrderCount();
@@ -5269,13 +5262,20 @@ void Compiler::ThreeOptLayout::Run()
52695262
}
52705263

52715264
assert(numCandidateBlocks < numBlocksUpperBound);
5272-
blockOrder[numCandidateBlocks] = tempOrder[numCandidateBlocks] = block;
5265+
blockOrder[numCandidateBlocks] = block;
52735266

52745267
// Repurpose 'bbPostorderNum' for the block's ordinal
52755268
block->bbPostorderNum = numCandidateBlocks++;
52765269
}
52775270

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();
52795279

52805280
if (modified)
52815281
{
@@ -5504,31 +5504,23 @@ bool Compiler::ThreeOptLayout::RunGreedyThreeOptPass(unsigned startPos, unsigned
55045504
}
55055505

55065506
//-----------------------------------------------------------------------------
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.
55085508
//
55095509
// Returns:
55105510
// True if we reordered anything, false otherwise
55115511
//
5512-
bool Compiler::ThreeOptLayout::RunThreeOptPass()
5512+
bool Compiler::ThreeOptLayout::RunThreeOpt()
55135513
{
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;
55245518

55255519
JITDUMP("Initial layout cost: %f\n", GetLayoutCost(startPos, endPos));
55265520
const bool modified = RunGreedyThreeOptPass(startPos, endPos);
55275521

5528-
// Write back to 'tempOrder' so changes to this region aren't lost next time we swap 'tempOrder' and 'blockOrder'
55295522
if (modified)
55305523
{
5531-
memcpy(tempOrder + startPos, blockOrder + startPos, sizeof(BasicBlock*) * numBlocks);
55325524
JITDUMP("Final layout cost: %f\n", GetLayoutCost(startPos, endPos));
55335525
}
55345526
else

0 commit comments

Comments
 (0)