[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp SelectionDAG.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Oct 4 23:48:00 PDT 2005



Changes in directory llvm/lib/CodeGen/SelectionDAG:

DAGCombiner.cpp updated: 1.17 -> 1.18
SelectionDAG.cpp updated: 1.196 -> 1.197
---
Log message:

implement visitBR_CC so that PowerPC/inverted-bool-compares.ll passes
with the dag combiner.  This speeds up espresso by 8%, reaching performance
parity with the dag-combiner-disabled llc.



---
Diffs of the changes:  (+25 -2)

 DAGCombiner.cpp  |   24 ++++++++++++++++++++++--
 SelectionDAG.cpp |    3 +++
 2 files changed, 25 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.17 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.18
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1.17	Wed Oct  5 01:35:28 2005
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp	Wed Oct  5 01:47:48 2005
@@ -1425,9 +1425,29 @@
   return SDOperand();
 }
 
+// Operand List for BR_CC: Chain, CondCC, CondLHS, CondRHS, DestBB.
+//
 SDOperand DAGCombiner::visitBR_CC(SDNode *N) {
-  // FIXME: come up with a common way between br_cc, brtwoway_cc, and select_cc
-  // to canonicalize the condition without calling getnode a bazillion times.
+  CondCodeSDNode *CC = cast<CondCodeSDNode>(N->getOperand(1));
+  SDOperand CondLHS = N->getOperand(2), CondRHS = N->getOperand(3);
+  
+  // Use SimplifySetCC  to simplify SETCC's.
+  SDOperand Simp = SimplifySetCC(MVT::i1, CondLHS, CondRHS, CC->get());
+  if (Simp.Val) {
+    if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Simp)) {
+      if (C->getValue() & 1) // Unconditional branch
+        return DAG.getNode(ISD::BR, MVT::Other, N->getOperand(0),
+                           N->getOperand(4));
+      else
+        return N->getOperand(0);          // Unconditional Fall through
+    } else if (Simp.Val->getOpcode() == ISD::SETCC) {
+      // Folded to a simpler setcc
+      return DAG.getNode(ISD::BR_CC, MVT::Other, N->getOperand(0), 
+                         Simp.getOperand(2), Simp.getOperand(0),
+                         Simp.getOperand(1), N->getOperand(4));
+    }
+  }
+  
   return SDOperand();
 }
 


Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.196 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.197
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.196	Wed Oct  5 01:37:22 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp	Wed Oct  5 01:47:48 2005
@@ -1963,6 +1963,9 @@
     assert(Ops.size() == 5 && "BR_CC takes 5 operands!");
     assert(Ops[2].getValueType() == Ops[3].getValueType() &&
            "LHS/RHS of comparison should match types!");
+    
+    if (CombinerEnabled) break;  // xforms moved to dag combine.
+    
     // Use SimplifySetCC  to simplify SETCC's.
     SDOperand Simp = SimplifySetCC(MVT::i1, Ops[2], Ops[3],
                                    cast<CondCodeSDNode>(Ops[1])->get());






More information about the llvm-commits mailing list