aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineBlockPlacement.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-11-27 20:18:00 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-11-27 20:18:00 +0000
commit51901d85f718a7e293f52a7908eab9fe1c0c94a0 (patch)
tree9b33dc7920aeee347fc57d356246390348abe553 /lib/CodeGen/MachineBlockPlacement.cpp
parent70e22016281508228a21dad6314ec96229af85d9 (diff)
Prevent rotating the blocks of a loop (and thus getting a backedge to be
fallthrough) in cases where we might fail to rotate an exit to an outer loop onto the end of the loop chain. Having *some* rotation, but not performing this rotation, is the primary fix of thep performance regression with -enable-block-placement for Olden/em3d (a whopping 30% regression). Still working on reducing the test case that actually exercises this and the new rotation strategy out of this code, but I want to check if this regresses other test cases first as that may indicate it isn't the correct fix. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145195 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r--lib/CodeGen/MachineBlockPlacement.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/CodeGen/MachineBlockPlacement.cpp b/lib/CodeGen/MachineBlockPlacement.cpp
index 56ad856b16..584290bd0f 100644
--- a/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/lib/CodeGen/MachineBlockPlacement.cpp
@@ -571,6 +571,11 @@ MachineBlockPlacement::findBestLoopTop(MachineFunction &F,
BlockFrequency BestExitEdgeFreq;
MachineBasicBlock *ExitingBB = 0;
MachineBasicBlock *LoopingBB = 0;
+ // If there are exits to outer loops, loop rotation can severely limit
+ // fallthrough opportunites unless it selects such an exit. Keep a set of
+ // blocks where rotating to exit with that block will reach an outer loop.
+ SmallPtrSet<MachineBasicBlock *, 4> BlocksExitingToOuterLoop;
+
DEBUG(dbgs() << "Finding best loop exit for: "
<< getBlockName(L.getHeader()) << "\n");
for (MachineLoop::block_iterator I = L.block_begin(),
@@ -641,6 +646,10 @@ MachineBlockPlacement::findBestLoopTop(MachineFunction &F,
BestExitEdgeFreq = ExitEdgeFreq;
ExitingBB = *I;
}
+
+ if (MachineLoop *ExitLoop = MLI->getLoopFor(*SI))
+ if (ExitLoop->contains(&L))
+ BlocksExitingToOuterLoop.insert(*I);
}
// Restore the old exiting state, no viable looping successor was found.
@@ -659,6 +668,13 @@ MachineBlockPlacement::findBestLoopTop(MachineFunction &F,
if (!ExitingBB || L.getNumBlocks() == 1)
return L.getHeader();
+ // Also, if we have exit blocks which lead to outer loops but didn't select
+ // one of them as the exiting block we are rotating toward, disable loop
+ // rotation altogether.
+ if (!BlocksExitingToOuterLoop.empty() &&
+ !BlocksExitingToOuterLoop.count(ExitingBB))
+ return L.getHeader();
+
assert(LoopingBB && "All successors of a loop block are exit blocks!");
DEBUG(dbgs() << " Best exiting block: " << getBlockName(ExitingBB) << "\n");
DEBUG(dbgs() << " Best top block: " << getBlockName(LoopingBB) << "\n");