Add support for promoting SETCC operations.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76987 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index cc8b510..3ccd915 100644
--- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -1641,11 +1641,16 @@
         case ISD::SETUGT:
         case ISD::SETUGE:
         case ISD::SETULT:
-        case ISD::SETULE:
-          return DAG.getSetCC(dl, VT, N0.getOperand(0),
-                          DAG.getConstant(APInt(C1).trunc(InSize),
-                                          N0.getOperand(0).getValueType()),
-                          Cond);
+        case ISD::SETULE: {
+          MVT newVT = N0.getOperand(0).getValueType();
+          if (DCI.isBeforeLegalizeOps() ||
+              (isOperationLegal(ISD::SETCC, newVT) &&
+               getCondCodeAction(Cond, newVT)==Legal))
+            return DAG.getSetCC(dl, VT, N0.getOperand(0),
+                                DAG.getConstant(APInt(C1).trunc(InSize), newVT),
+                                Cond);
+          break;
+        }
         default:
           break;   // todo, be more careful with signed comparisons
         }