diff options
| author | Tim Northover <tnorthover@apple.com> | 2014-11-13 17:58:51 +0000 |
|---|---|---|
| committer | Tim Northover <tnorthover@apple.com> | 2014-11-13 17:58:51 +0000 |
| commit | ab85dcc7b8d14edf8f2e716850739cfeb5bf0ccd (patch) | |
| tree | b7f89e1b37fca17b61420f1a01b4695c41cd5f17 /llvm/lib | |
| parent | 650b0ee53b738d8e11370ac5baf9fc2c7d0cede3 (diff) | |
| download | bcm5719-llvm-ab85dcc7b8d14edf8f2e716850739cfeb5bf0ccd.tar.gz bcm5719-llvm-ab85dcc7b8d14edf8f2e716850739cfeb5bf0ccd.zip | |
ARM: avoid duplicating branches during constant islands.
We were using a naive heuristic to determine whether a basic block already had
an unconditional branch at the end. This mostly corresponded to reality
(assuming branches got optimised) because there's not much point in a branch to
the next block, but could go wrong.
llvm-svn: 221904
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Target/ARM/ARMConstantIslandPass.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp index fa9bfa2b327..1d3ca1a9ce3 100644 --- a/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp +++ b/llvm/lib/Target/ARM/ARMConstantIslandPass.cpp @@ -275,6 +275,7 @@ namespace { private: void doInitialPlacement(std::vector<MachineInstr*> &CPEMIs); + bool BBHasFallthrough(MachineBasicBlock *MBB); CPEntry *findConstPoolEntry(unsigned CPI, const MachineInstr *CPEMI); unsigned getCPELogAlign(const MachineInstr *CPEMI); void scanFunctionJumpTables(); @@ -566,7 +567,7 @@ ARMConstantIslands::doInitialPlacement(std::vector<MachineInstr*> &CPEMIs) { /// BBHasFallthrough - Return true if the specified basic block can fallthrough /// into the block immediately after it. -static bool BBHasFallthrough(MachineBasicBlock *MBB) { +bool ARMConstantIslands::BBHasFallthrough(MachineBasicBlock *MBB) { // Get the next machine basic block in the function. MachineFunction::iterator MBBI = MBB; // Can't fall off end of function. @@ -574,12 +575,15 @@ static bool BBHasFallthrough(MachineBasicBlock *MBB) { return false; MachineBasicBlock *NextBB = std::next(MBBI); - for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), - E = MBB->succ_end(); I != E; ++I) - if (*I == NextBB) - return true; + if (std::find(MBB->succ_begin(), MBB->succ_end(), NextBB) == MBB->succ_end()) + return false; - return false; + // Try to analyze the end of the block. A potential fallthrough may already + // have an unconditional branch for whatever reason. + MachineBasicBlock *TBB, *FBB; + SmallVector<MachineOperand, 4> Cond; + bool TooDifficult = TII->AnalyzeBranch(*MBB, TBB, FBB, Cond); + return TooDifficult || FBB == nullptr; } /// findConstPoolEntry - Given the constpool index and CONSTPOOL_ENTRY MI, |

