summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/BranchFolding.cpp
diff options
context:
space:
mode:
authorHaicheng Wu <haicheng@codeaurora.org>2016-08-12 03:30:23 +0000
committerHaicheng Wu <haicheng@codeaurora.org>2016-08-12 03:30:23 +0000
commitea0237205990c6652929331cf07702add46f377d (patch)
tree8c13ea08a1f110b004eceb5860446fee4786e33d /llvm/lib/CodeGen/BranchFolding.cpp
parent7ad9d6d2f0a0bf472455ccdc41e919f4165a7e1f (diff)
downloadbcm5719-llvm-ea0237205990c6652929331cf07702add46f377d.tar.gz
bcm5719-llvm-ea0237205990c6652929331cf07702add46f377d.zip
[BranchFolding] Restrict tail merging loop blocks after MBP
To fix PR28014, this patch restricts tail merging to blocks that belong to the same loop after MBP. Differential Revision: https://reviews.llvm.org/D23191 llvm-svn: 278463
Diffstat (limited to 'llvm/lib/CodeGen/BranchFolding.cpp')
-rw-r--r--llvm/lib/CodeGen/BranchFolding.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp
index 1a783b61276..a2d304bb078 100644
--- a/llvm/lib/CodeGen/BranchFolding.cpp
+++ b/llvm/lib/CodeGen/BranchFolding.cpp
@@ -1005,6 +1005,24 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
MachineBasicBlock *IBB = &*I;
MachineBasicBlock *PredBB = &*std::prev(I);
MergePotentials.clear();
+ MachineLoop *ML;
+
+ // Bail if merging after placement and IBB is the loop header because
+ // -- If merging predecessors that belong to the same loop as IBB, the
+ // common tail of merged predecessors may become the loop top if block
+ // placement is called again and the predecessors may branch to this common
+ // tail and require more branches. This can be relaxed if
+ // MachineBlockPlacement::findBestLoopTop is more flexible.
+ // --If merging predecessors that do not belong to the same loop as IBB, the
+ // loop info of IBB's loop and the other loops may be affected. Calling the
+ // block placement again may make big change to the layout and eliminate the
+ // reason to do tail merging here.
+ if (AfterBlockPlacement && MLI) {
+ ML = MLI->getLoopFor(IBB);
+ if (ML && IBB == ML->getHeader())
+ continue;
+ }
+
for (MachineBasicBlock *PBB : I->predecessors()) {
if (MergePotentials.size() == TailMergeThreshold)
break;
@@ -1024,16 +1042,12 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
if (PBB->hasEHPadSuccessor())
continue;
- // Bail out if the loop header (IBB) is not the top of the loop chain
- // after the block placement. Otherwise, the common tail of IBB's
- // predecessors may become the loop top if block placement is called again
- // and the predecessors may branch to this common tail.
- // FIXME: Relaxed this check if the algorithm of finding loop top is
- // changed in MBP.
+ // After block placement, only consider predecessors that belong to the
+ // same loop as IBB. The reason is the same as above when skipping loop
+ // header.
if (AfterBlockPlacement && MLI)
- if (MachineLoop *ML = MLI->getLoopFor(IBB))
- if (IBB == ML->getHeader() && ML == MLI->getLoopFor(PBB))
- continue;
+ if (ML != MLI->getLoopFor(PBB))
+ continue;
MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
SmallVector<MachineOperand, 4> Cond;
OpenPOWER on IntegriCloud