Skip to content

Commit

Permalink
[MBP] Prevent rotating a chain contains entry block
Browse files Browse the repository at this point in the history
The entry block should always be the first BB in a function.
So we should not rotate a chain contains the entry block.

Differential Revision: https://reviews.llvm.org/D92882
  • Loading branch information
weiguozhi committed Dec 14, 2020
1 parent f5fe849 commit d50d7c3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion llvm/lib/CodeGen/MachineBlockPlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2306,6 +2306,10 @@ void MachineBlockPlacement::rotateLoop(BlockChain &LoopChain,
if (Bottom == ExitingBB)
return;

// The entry block should always be the first BB in a function.
if (Top->isEntryBlock())
return;

bool ViableTopFallthrough = hasViableTopFallthrough(Top, LoopBlockSet);

// If the header has viable fallthrough, check whether the current loop
Expand Down Expand Up @@ -2380,6 +2384,11 @@ void MachineBlockPlacement::rotateLoopWithProfile(
BlockChain &LoopChain, const MachineLoop &L,
const BlockFilterSet &LoopBlockSet) {
auto RotationPos = LoopChain.end();
MachineBasicBlock *ChainHeaderBB = *LoopChain.begin();

// The entry block should always be the first BB in a function.
if (ChainHeaderBB->isEntryBlock())
return;

BlockFrequency SmallestRotationCost = BlockFrequency::getMaxFrequency();

Expand All @@ -2398,7 +2407,6 @@ void MachineBlockPlacement::rotateLoopWithProfile(
// chain head is not the loop header. As we only consider natural loops with
// single header, this computation can be done only once.
BlockFrequency HeaderFallThroughCost(0);
MachineBasicBlock *ChainHeaderBB = *LoopChain.begin();
for (auto *Pred : ChainHeaderBB->predecessors()) {
BlockChain *PredChain = BlockToChain[Pred];
if (!LoopBlockSet.count(Pred) &&
Expand Down

0 comments on commit d50d7c3

Please sign in to comment.