diff options
author | Chris Lattner <sabre@nondot.org> | 2006-10-27 21:54:23 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-10-27 21:54:23 +0000 |
commit | d2f9ee9ea7b08c23a8742b6a53dd78a20233adc0 (patch) | |
tree | fc3c13193c3f3f95f83ba3db39de4e087fee1f23 | |
parent | 00ef5047974e362229dd822716d52651c3db4f9a (diff) |
Codegen cond&cond with two branches. This compiles (f.e.) PowerPC/and-branch.ll to:
cmpwi cr0, r4, 4
bgt cr0, LBB1_2 ;UnifiedReturnBlock
LBB1_3: ;entry
cmplwi cr0, r3, 0
bne cr0, LBB1_2 ;UnifiedReturnBlock
instead of:
cmpwi cr7, r4, 4
mfcr r2
addic r4, r3, -1
subfe r3, r4, r3
rlwinm r2, r2, 30, 31, 31
or r2, r2, r3
cmplwi cr0, r2, 0
bne cr0, LBB1_2 ;UnifiedReturnBlock
LBB1_1: ;cond_true
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31232 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 8024fcac46..664979512f 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -888,22 +888,43 @@ void SelectionDAGLowering::FindMergedConditions(Value *Cond, return; } - // Codegen X | Y as: - // jmp_if_X TBB - // TmpBB: - // jmp_if_Y TBB - // jmp FBB - // - // This requires creation of TmpBB after CurBB. + + // Create TmpBB after CurBB. MachineFunction::iterator BBI = CurBB; MachineBasicBlock *TmpBB = new MachineBasicBlock(CurBB->getBasicBlock()); CurBB->getParent()->getBasicBlockList().insert(++BBI, TmpBB); - // Emit the LHS condition. - FindMergedConditions(BOp->getOperand(0), TBB, TmpBB, CurBB, Opc); + if (Opc == Instruction::Or) { + // Codegen X | Y as: + // jmp_if_X TBB + // jmp TmpBB + // TmpBB: + // jmp_if_Y TBB + // jmp FBB + // - // Emit the RHS condition into TmpBB. - FindMergedConditions(BOp->getOperand(1), TBB, FBB, TmpBB, Opc); + // Emit the LHS condition. + FindMergedConditions(BOp->getOperand(0), TBB, TmpBB, CurBB, Opc); + + // Emit the RHS condition into TmpBB. + FindMergedConditions(BOp->getOperand(1), TBB, FBB, TmpBB, Opc); + } else { + assert(Opc == Instruction::And && "Unknown merge op!"); + // Codegen X & Y as: + // jmp_if_X TmpBB + // jmp FBB + // TmpBB: + // jmp_if_Y TBB + // jmp FBB + // + // This requires creation of TmpBB after CurBB. + + // Emit the LHS condition. + FindMergedConditions(BOp->getOperand(0), TmpBB, FBB, CurBB, Opc); + + // Emit the RHS condition into TmpBB. + FindMergedConditions(BOp->getOperand(1), TBB, FBB, TmpBB, Opc); + } } void SelectionDAGLowering::visitBr(BranchInst &I) { @@ -950,12 +971,11 @@ void SelectionDAGLowering::visitBr(BranchInst &I) { // if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(CondVal)) { if (BOp->hasOneUse() && - (/*BOp->getOpcode() == Instruction::And ||*/ + (BOp->getOpcode() == Instruction::And || BOp->getOpcode() == Instruction::Or)) { + if (BOp->getOpcode() == Instruction::And) + I.getParent()->dump(); FindMergedConditions(BOp, Succ0MBB, Succ1MBB, CurMBB, BOp->getOpcode()); - //std::cerr << "FOUND: " << SwitchCases.size() << " merged conditions:\n"; - //I.getParent()->dump(); - visitSwitchCase(SwitchCases[0]); SwitchCases.erase(SwitchCases.begin()); return; |