If the false case is the current basic block, then this is a self loop.
authorEvan Cheng <evan.cheng@apple.com>
Thu, 16 Feb 2006 08:27:56 +0000 (08:27 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Thu, 16 Feb 2006 08:27:56 +0000 (08:27 +0000)
We do not want to emit "Loop: ... brcond Out; br Loop", as it adds an extra
instruction in the loop.  Instead, invert the condition and emit
"Loop: ... br!cond Loop; br Out.

Generalize the fix by moving it from PPCDAGToDAGISel to SelectionDAGLowering.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26231 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/Target/PowerPC/PPCISelDAGToDAG.cpp

index 766f846968909eed4906a3075a4db5f6cb291bdc..78f5623aed9d42ebcc0535fbcbe5387068bd9b5b 100644 (file)
@@ -562,6 +562,15 @@ void SelectionDAGLowering::visitBr(BranchInst &I) {
     } else {
       std::vector<SDOperand> Ops;
       Ops.push_back(getRoot());
+      // If the false case is the current basic block, then this is a self
+      // loop. We do not want to emit "Loop: ... brcond Out; br Loop", as it
+      // adds an extra instruction in the loop.  Instead, invert the
+      // condition and emit "Loop: ... br!cond Loop; br Out. 
+      if (CurMBB == Succ1MBB) {
+        std::swap(Succ0MBB, Succ1MBB);
+        SDOperand True = DAG.getConstant(1, Cond.getValueType());
+        Cond = DAG.getNode(ISD::XOR, Cond.getValueType(), Cond, True);
+      }
       Ops.push_back(Cond);
       Ops.push_back(DAG.getBasicBlock(Succ0MBB));
       Ops.push_back(DAG.getBasicBlock(Succ1MBB));
index 08fdcb46603fffdc04e37f3d6e591690d483cb3b..b781ca5cd8f4494831b88f2b4ba89dafdfe18067 100644 (file)
@@ -1046,17 +1046,6 @@ void PPCDAGToDAGISel::Select(SDOperand &Result, SDOperand Op) {
     if (N->getOpcode() == ISD::BRTWOWAY_CC) {
       SDOperand CondTrueBlock = N->getOperand(4);
       SDOperand CondFalseBlock = N->getOperand(5);
-      
-      // If the false case is the current basic block, then this is a self loop.
-      // We do not want to emit "Loop: ... brcond Out; br Loop", as it adds an
-      // extra dispatch group to the loop.  Instead, invert the condition and
-      // emit "Loop: ... br!cond Loop; br Out
-      if (cast<BasicBlockSDNode>(CondFalseBlock)->getBasicBlock() == BB) {
-        std::swap(CondTrueBlock, CondFalseBlock);
-        CC = getSetCCInverse(CC,
-                             MVT::isInteger(N->getOperand(2).getValueType()));
-      }
-      
       unsigned Opc = getBCCForSetCC(CC);
       SDOperand CB =
         SDOperand(CurDAG->getTargetNode(PPC::COND_BRANCH, MVT::Other,