summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorQuentin Colombet <qcolombet@apple.com>2016-05-02 22:58:59 +0000
committerQuentin Colombet <qcolombet@apple.com>2016-05-02 22:58:59 +0000
commit776e6de51626b01b6e4d062c243e48bcc9446884 (patch)
treeee315b33525a5506702831b78fd6e1c2572561bd /llvm/lib
parent4e1d389ac5cf5048d2c4e90caa2de672d7445148 (diff)
downloadbcm5719-llvm-776e6de51626b01b6e4d062c243e48bcc9446884.tar.gz
bcm5719-llvm-776e6de51626b01b6e4d062c243e48bcc9446884.zip
[MachineBlockPlacement] Let the target optimize the branches at the end.
After the layout of the basic blocks is set, the target may be able to get rid of unconditional branches to fallthrough blocks that the generic code does not catch. This happens any time TargetInstrInfo::AnalyzeBranch is not able to analyze all the branches involved in the terminators sequence, while still understanding a few of them. In such situation, AnalyzeBranch can directly modify the branches if it has been instructed to do so. This patch takes advantage of that. llvm-svn: 268328
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index baa9df6c5f1..fb722a166a0 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -1358,6 +1358,19 @@ void MachineBlockPlacement::buildCFGChains(MachineFunction &F) {
MachineBasicBlock *TBB = nullptr, *FBB = nullptr; // For AnalyzeBranch.
if (!TII->AnalyzeBranch(F.back(), TBB, FBB, Cond))
F.back().updateTerminator();
+
+ // Now that all the basic blocks in the chain have the proper layout,
+ // make a final call to AnalyzeBranch with AllowModify set.
+ // Indeed, the target may be able to optimize the branches in a way we
+ // cannot because all branches may not be analyzable.
+ // E.g., the target may be able to remove an unconditional branch to
+ // a fallthrough when it occurs after predicated terminators.
+ for (MachineBasicBlock *ChainBB : FunctionChain) {
+ Cond.clear();
+ TBB = nullptr;
+ FBB = nullptr; // For AnalyzeBranch.
+ (void)TII->AnalyzeBranch(*ChainBB, TBB, FBB, Cond, /*AllowModify*/ true);
+ }
}
void MachineBlockPlacement::alignBlocks(MachineFunction &F) {
OpenPOWER on IntegriCloud