diff options
author | Dan Gohman <gohman@apple.com> | 2008-10-02 22:15:21 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2008-10-02 22:15:21 +0000 |
commit | d98d6203e429b2d7208b6687931e9079e85e95ec (patch) | |
tree | e744407259a2a06f8edace7287f97f48d23d3c3d /lib/CodeGen | |
parent | 6ade6f55a836129af634074e96f660ff23f59a30 (diff) | |
download | external_llvm-d98d6203e429b2d7208b6687931e9079e85e95ec.zip external_llvm-d98d6203e429b2d7208b6687931e9079e85e95ec.tar.gz external_llvm-d98d6203e429b2d7208b6687931e9079e85e95ec.tar.bz2 |
Optimize conditional branches in X86FastISel. This replaces
sequences like this:
sete %al
testb %al, %al
jne LBB11_1
with this:
je LBB11_1
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/SelectionDAG/FastISel.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index 9f70bc9..c0e8418 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -461,6 +461,23 @@ FastISel::SelectInstruction(Instruction *I) { return SelectOperator(I, I->getOpcode()); } +/// FastEmitBranch - Emit an unconditional branch to the given block, +/// unless it is the immediate (fall-through) successor, and update +/// the CFG. +void +FastISel::FastEmitBranch(MachineBasicBlock *MSucc) { + MachineFunction::iterator NextMBB = + next(MachineFunction::iterator(MBB)); + + if (MBB->isLayoutSuccessor(MSucc)) { + // The unconditional fall-through case, which needs no instructions. + } else { + // The unconditional branch case. + TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>()); + } + MBB->addSuccessor(MSucc); +} + bool FastISel::SelectOperator(User *I, unsigned Opcode) { switch (Opcode) { @@ -508,18 +525,9 @@ FastISel::SelectOperator(User *I, unsigned Opcode) { BranchInst *BI = cast<BranchInst>(I); if (BI->isUnconditional()) { - MachineFunction::iterator NextMBB = - next(MachineFunction::iterator(MBB)); BasicBlock *LLVMSucc = BI->getSuccessor(0); MachineBasicBlock *MSucc = MBBMap[LLVMSucc]; - - if (NextMBB != MF.end() && MSucc == NextMBB) { - // The unconditional fall-through case, which needs no instructions. - } else { - // The unconditional branch case. - TII.InsertBranch(*MBB, MSucc, NULL, SmallVector<MachineOperand, 0>()); - } - MBB->addSuccessor(MSucc); + FastEmitBranch(MSucc); return true; } |