Legalize ConstantFP into TargetConstantFP when the target allows. Implement
authorChris Lattner <sabre@nondot.org>
Sun, 29 Jan 2006 06:26:56 +0000 (06:26 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 29 Jan 2006 06:26:56 +0000 (06:26 +0000)
custom expansion of ConstantFP nodes.

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

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index f89b237c053fb5c0d9c96975334ef88570b66777..89d764cc6cd664f946969088422cf592d8d0ed9a 100644 (file)
@@ -272,6 +272,8 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
   case ISD::BasicBlock:
   case ISD::TargetFrameIndex:
   case ISD::TargetConstant:
+  case ISD::TargetConstantFP:
+  case ISD::TargetConstantVec:
   case ISD::TargetConstantPool:
   case ISD::TargetGlobalAddress:
   case ISD::TargetExternalSymbol:
@@ -481,7 +483,22 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
         break;
       }
 
-    if (!isLegal) {
+    // If this is a legal constant, turn it into a TargetConstantFP node.
+    if (isLegal) {
+      Result = DAG.getTargetConstantFP(CFP->getValue(), CFP->getValueType(0));
+      break;
+    }
+
+    switch (TLI.getOperationAction(ISD::ConstantFP, CFP->getValueType(0))) {
+    default: assert(0 && "This action is not supported yet!");
+    case TargetLowering::Custom:
+      Tmp3 = TLI.LowerOperation(Result, DAG);
+      if (Tmp3.Val) {
+        Result = Tmp3;
+        break;
+      }
+      // FALLTHROUGH
+    case TargetLowering::Expand:
       // Otherwise we need to spill the constant to memory.
       bool Extend = false;
 
index 1b12d3117316147c9fa3769b44d446c24e1daf0c..b9a6ec0d452e291704fd505fbf9bfb175ede5252 100644 (file)
@@ -277,6 +277,11 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
     Erased = ConstantFPs.erase(std::make_pair(V, N->getValueType(0)));
     break;
   }
+  case ISD::TargetConstantFP: {
+    uint64_t V = DoubleToBits(cast<ConstantFPSDNode>(N)->getValue());
+    Erased = TargetConstantFPs.erase(std::make_pair(V, N->getValueType(0)));
+    break;
+  }
   case ISD::STRING:
     Erased = StringNodes.erase(cast<StringSDNode>(N)->getValue());
     break;
@@ -606,7 +611,22 @@ SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT) {
   // we don't have issues with SNANs.
   SDNode *&N = ConstantFPs[std::make_pair(DoubleToBits(Val), VT)];
   if (N) return SDOperand(N, 0);
-  N = new ConstantFPSDNode(Val, VT);
+  N = new ConstantFPSDNode(false, Val, VT);
+  AllNodes.push_back(N);
+  return SDOperand(N, 0);
+}
+
+SDOperand SelectionDAG::getTargetConstantFP(double Val, MVT::ValueType VT) {
+  assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!");
+  if (VT == MVT::f32)
+    Val = (float)Val;  // Mask out extra precision.
+  
+  // Do the map lookup using the actual bit pattern for the floating point
+  // value, so that we don't have problems with 0.0 comparing equal to -0.0, and
+  // we don't have issues with SNANs.
+  SDNode *&N = TargetConstantFPs[std::make_pair(DoubleToBits(Val), VT)];
+  if (N) return SDOperand(N, 0);
+  N = new ConstantFPSDNode(true, Val, VT);
   AllNodes.push_back(N);
   return SDOperand(N, 0);
 }