Codegen cond&cond with two branches. This compiles (f.e.) PowerPC/and-branch.ll to:
authorChris Lattner <sabre@nondot.org>
Fri, 27 Oct 2006 21:54:23 +0000 (21:54 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 27 Oct 2006 21:54:23 +0000 (21:54 +0000)
        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

lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

index 8024fcac46c04045d8fbbd09261b8f6d4f956250..664979512f2c64dd8bf8f62a64879d64718a74b3 100644 (file)
@@ -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;