Fix a major bug in setcc/cmov folding, where we accidentally
authorChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 03:37:59 +0000 (03:37 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 11 Jan 2005 03:37:59 +0000 (03:37 +0000)
inverted the sense of the comparison.

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

lib/Target/X86/X86ISelPattern.cpp

index a70305a7e1c10f087b4da8fd6965c4a6fb9203bb..7a1b5a6972f2120f8d7adcd9a3a3ac9d906f44ce 100644 (file)
@@ -379,6 +379,9 @@ unsigned ISel::ComputeRegPressure(SDOperand O) {
   unsigned &Result = RegPressureMap[N];
   if (Result) return Result;
 
+  // FIXME: Should operations like CALL (which clobber lots o regs) have a
+  // higher fixed cost??
+
   if (N->getNumOperands() == 0)
     return Result = 1;
 
@@ -771,6 +774,7 @@ void ISel::EmitSelectCC(SDOperand Cond, MVT::ValueType SVT,
   } else {
     // FIXME: CMP R, 0 -> TEST R, R
     EmitCMP(Cond.getOperand(0), Cond.getOperand(1));
+    std::swap(RTrue, RFalse);
   }
   BuildMI(BB, Opc, 2, RDest).addReg(RTrue).addReg(RFalse);
 }
@@ -1438,7 +1442,6 @@ unsigned ISel::SelectExpr(SDOperand N) {
     return Result;
 
   case ISD::SELECT:
-    // FIXME: implement folding of setcc into select.
     if (N.getValueType() != MVT::i1 && N.getValueType() != MVT::i8) {
       if (getRegPressure(N.getOperand(1)) > getRegPressure(N.getOperand(2))) {
         Tmp2 = SelectExpr(N.getOperand(1));
@@ -1452,10 +1455,17 @@ unsigned ISel::SelectExpr(SDOperand N) {
     } else {
       // FIXME: This should not be implemented here, it should be in the generic
       // code!
-      Tmp2 = SelectExpr(CurDAG->getNode(ISD::ZERO_EXTEND, MVT::i16,
-                                        N.getOperand(1)));
-      Tmp3 = SelectExpr(CurDAG->getNode(ISD::ZERO_EXTEND, MVT::i16,
-                                        N.getOperand(2)));
+      if (getRegPressure(N.getOperand(1)) > getRegPressure(N.getOperand(2))) {
+        Tmp2 = SelectExpr(CurDAG->getNode(ISD::ZERO_EXTEND, MVT::i16,
+                                          N.getOperand(1)));
+        Tmp3 = SelectExpr(CurDAG->getNode(ISD::ZERO_EXTEND, MVT::i16,
+                                          N.getOperand(2)));
+      } else {
+        Tmp3 = SelectExpr(CurDAG->getNode(ISD::ZERO_EXTEND, MVT::i16,
+                                          N.getOperand(2)));
+        Tmp2 = SelectExpr(CurDAG->getNode(ISD::ZERO_EXTEND, MVT::i16,
+                                          N.getOperand(1)));
+      }
       unsigned TmpReg = MakeReg(MVT::i16);
       EmitSelectCC(N.getOperand(0), MVT::i16, Tmp2, Tmp3, TmpReg);
       // FIXME: need subregs to do better than this!
@@ -1971,7 +1981,7 @@ void ISel::Select(SDOperand N) {
       default: assert(0 && "Unknown operand number!");
       case 0: Select(N.getOperand(0)); break;
       case 1: Tmp1 = SelectExpr(N.getOperand(1)); break;
-      case 2: SelectAddress(N.getOperand(2), AM);
+      case 2: SelectAddress(N.getOperand(2), AM); break;
       }
 
     addFullAddress(BuildMI(BB, Opc, 4+1), AM).addReg(Tmp1);