[llvm-commits] [llvm] r72509 - /llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Eli Friedman eli.friedman at gmail.com
Wed May 27 20:06:19 PDT 2009


Author: efriedma
Date: Wed May 27 22:06:16 2009
New Revision: 72509

URL: http://llvm.org/viewvc/llvm-project?rev=72509&view=rev
Log:
Some minor cleanups.


Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=72509&r1=72508&r2=72509&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Wed May 27 22:06:16 2009
@@ -740,15 +740,31 @@
     Action = TLI.getOperationAction(Node->getOpcode(), InnerType);
     break;
   }
+  case ISD::SELECT_CC:
+  case ISD::SETCC:
+  case ISD::BR_CC: {
+    unsigned CCOperand = Node->getOpcode() == ISD::SELECT_CC ? 4 :
+                         Node->getOpcode() == ISD::SETCC ? 2 : 1;
+    unsigned CompareOperand = Node->getOpcode() == ISD::BR_CC ? 2 : 0;
+    MVT OpVT = Node->getOperand(CompareOperand).getValueType();
+    ISD::CondCode CCCode =
+        cast<CondCodeSDNode>(Node->getOperand(CCOperand))->get();
+    Action = TLI.getCondCodeAction(CCCode, OpVT);
+    if (Action == TargetLowering::Legal) {
+      if (Node->getOpcode() == ISD::SELECT_CC)
+        Action = TLI.getOperationAction(Node->getOpcode(),
+                                        Node->getValueType(0));
+      else
+        Action = TLI.getOperationAction(Node->getOpcode(), OpVT);
+    }
+    break;
+  }
   case ISD::LOAD:
   case ISD::STORE:
-  case ISD::BR_CC:
   case ISD::FORMAL_ARGUMENTS:
   case ISD::CALL:
   case ISD::CALLSEQ_START:
   case ISD::CALLSEQ_END:
-  case ISD::SELECT_CC:
-  case ISD::SETCC:
     // These instructions have properties that aren't modeled in the
     // generic codepath
     SimpleFinishLegalizing = false;
@@ -2215,31 +2231,17 @@
     assert(NewInTy.isInteger() && "Ran out of possibilities!");
 
     // If the target supports SINT_TO_FP of this type, use it.
-    switch (TLI.getOperationAction(ISD::SINT_TO_FP, NewInTy)) {
-      default: break;
-      case TargetLowering::Legal:
-        if (!TLI.isTypeLegal(NewInTy))
-          break;  // Can't use this datatype.
-        // FALL THROUGH.
-      case TargetLowering::Custom:
-        OpToUse = ISD::SINT_TO_FP;
-        break;
+    if (TLI.isOperationLegalOrCustom(ISD::SINT_TO_FP, NewInTy)) {
+      OpToUse = ISD::SINT_TO_FP;
+      break;
     }
-    if (OpToUse) break;
     if (isSigned) continue;
 
     // If the target supports UINT_TO_FP of this type, use it.
-    switch (TLI.getOperationAction(ISD::UINT_TO_FP, NewInTy)) {
-      default: break;
-      case TargetLowering::Legal:
-        if (!TLI.isTypeLegal(NewInTy))
-          break;  // Can't use this datatype.
-        // FALL THROUGH.
-      case TargetLowering::Custom:
-        OpToUse = ISD::UINT_TO_FP;
-        break;
+    if (TLI.isOperationLegalOrCustom(ISD::UINT_TO_FP, NewInTy)) {
+      OpToUse = ISD::UINT_TO_FP;
+      break;
     }
-    if (OpToUse) break;
 
     // Otherwise, try a larger type.
   }
@@ -2270,31 +2272,15 @@
     NewOutTy = (MVT::SimpleValueType)(NewOutTy.getSimpleVT()+1);
     assert(NewOutTy.isInteger() && "Ran out of possibilities!");
 
-    // If the target supports FP_TO_SINT returning this type, use it.
-    switch (TLI.getOperationAction(ISD::FP_TO_SINT, NewOutTy)) {
-    default: break;
-    case TargetLowering::Legal:
-      if (!TLI.isTypeLegal(NewOutTy))
-        break;  // Can't use this datatype.
-      // FALL THROUGH.
-    case TargetLowering::Custom:
+    if (TLI.isOperationLegalOrCustom(ISD::FP_TO_SINT, NewOutTy)) {
       OpToUse = ISD::FP_TO_SINT;
       break;
     }
-    if (OpToUse) break;
 
-    // If the target supports FP_TO_UINT of this type, use it.
-    switch (TLI.getOperationAction(ISD::FP_TO_UINT, NewOutTy)) {
-    default: break;
-    case TargetLowering::Legal:
-      if (!TLI.isTypeLegal(NewOutTy))
-        break;  // Can't use this datatype.
-      // FALL THROUGH.
-    case TargetLowering::Custom:
+    if (TLI.isOperationLegalOrCustom(ISD::FP_TO_UINT, NewOutTy)) {
       OpToUse = ISD::FP_TO_UINT;
       break;
     }
-    if (OpToUse) break;
 
     // Otherwise, try a larger type.
   }
@@ -2303,16 +2289,6 @@
   // Okay, we found the operation and type to use.
   SDValue Operation = DAG.getNode(OpToUse, dl, NewOutTy, LegalOp);
 
-  // If the operation produces an invalid type, it must be custom lowered.  Use
-  // the target lowering hooks to expand it.  Just keep the low part of the
-  // expanded operation, we know that we're truncating anyway.
-  if (getTypeAction(NewOutTy) == Expand) {
-    SmallVector<SDValue, 2> Results;
-    TLI.ReplaceNodeResults(Operation.getNode(), Results, DAG);
-    assert(Results.size() == 1 && "Incorrect FP_TO_XINT lowering!");
-    Operation = Results[0];
-  }
-
   // Truncate the result of the extended FP_TO_*INT operation to the desired
   // size.
   return DAG.getNode(ISD::TRUNCATE, dl, DestVT, Operation);
@@ -2844,13 +2820,13 @@
     unsigned DivRemOpc = isSigned ? ISD::SDIVREM : ISD::UDIVREM;
     Tmp2 = Node->getOperand(0);
     Tmp3 = Node->getOperand(1);
-    if (TLI.getOperationAction(DivOpc, VT) == TargetLowering::Legal) {
+    if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
+      Tmp1 = DAG.getNode(DivRemOpc, dl, VTs, Tmp2, Tmp3).getValue(1);
+    } else if (TLI.isOperationLegalOrCustom(DivOpc, VT)) {
       // X % Y -> X-X/Y*Y
       Tmp1 = DAG.getNode(DivOpc, dl, VT, Tmp2, Tmp3);
       Tmp1 = DAG.getNode(ISD::MUL, dl, VT, Tmp1, Tmp3);
       Tmp1 = DAG.getNode(ISD::SUB, dl, VT, Tmp2, Tmp1);
-    } else if (TLI.isOperationLegalOrCustom(DivRemOpc, VT)) {
-      Tmp1 = DAG.getNode(DivRemOpc, dl, VTs, Tmp2, Tmp3).getValue(1);
     } else if (isSigned) {
       Tmp1 = ExpandIntLibCall(Node, true, RTLIB::SREM_I16, RTLIB::SREM_I32,
                               RTLIB::SREM_I64, RTLIB::SREM_I128);





More information about the llvm-commits mailing list