1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

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
This commit is contained in:
Tim Northover 2014-11-13 17:58:51 +00:00
parent 5807daa475
commit a52b6a893f
2 changed files with 35 additions and 6 deletions

View File

@ -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,

View File

@ -0,0 +1,25 @@
; RUN: llc -mtriple=thumbv7-linux-gnueabihf -O0 -fast-isel=0 -o - %s | FileCheck %s
define void @test_no_duplicate_branches(float %in) {
; CHECK-LABEL: test_no_duplicate_branches:
; CHECK: vldr {{s[0-9]+}}, [[CONST:\.LCPI[0-9]+_[0-9]+]]
; CHECK: b .LBB
; CHECK-NOT: b .LBB
; CHECK: [[CONST]]:
; CHECK-NEXT: .long 1150963712
%tst = fcmp oeq float %in, 1234.5
%chain = zext i1 %tst to i32
br i1 %tst, label %true, label %false
true:
call i32 @llvm.arm.space(i32 2000, i32 undef)
ret void
false:
ret void
}
declare i32 @llvm.arm.space(i32, i32)