[llvm-commits] [llvm] r41407 - in /llvm/trunk: include/llvm/CodeGen/SelectionDAGNodes.h lib/CodeGen/SelectionDAG/DAGCombiner.cpp lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Dale Johannesen dalej at apple.com
Sat Aug 25 15:10:57 PDT 2007


Author: johannes
Date: Sat Aug 25 17:10:57 2007
New Revision: 41407

URL: http://llvm.org/viewvc/llvm-project?rev=41407&view=rev
Log:
Add APFloat interface to ConstantFPSDNode.  Change
over uses in DAGCombiner.  Fix interfaces to work
with APFloats.

Modified:
    llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Modified: llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h?rev=41407&r1=41406&r2=41407&view=diff

==============================================================================
--- llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h Sat Aug 25 17:10:57 2007
@@ -1151,17 +1151,36 @@
   friend class SelectionDAG;
   ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
-             getSDVTList(VT)), Value(APFloat(val)) {
+             getSDVTList(VT)), 
+             Value(VT==MVT::f64 ? APFloat(val) : APFloat((float)val)) {
+  }
+  ConstantFPSDNode(bool isTarget, APFloat val, MVT::ValueType VT)
+    : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
+             getSDVTList(VT)), Value(val) {
   }
 public:
 
-  double getValue() const { return Value.convertToDouble(); }
+  // Longterm plan: replace all uses of getValue with getValueAPF, remove
+  // getValue, rename getValueAPF to getValue.
+  double getValue() const { 
+    if ( getValueType(0)==MVT::f64)
+      return Value.convertToDouble();
+    else
+      return Value.convertToFloat();
+  }
+  APFloat getValueAPF() const { return Value; }
 
   /// isExactlyValue - We don't rely on operator== working on double values, as
   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
   /// As such, this method can be used to do an exact bit-for-bit comparison of
   /// two floating point values.
-  bool isExactlyValue(double V) const;
+  bool isExactlyValue(double V) const { 
+    if (getValueType(0)==MVT::f64)
+      return isExactlyValue(APFloat(V));
+    else
+      return isExactlyValue(APFloat((float)V));
+  }
+  bool isExactlyValue(APFloat V) const;
 
   static bool classof(const ConstantFPSDNode *) { return true; }
   static bool classof(const SDNode *N) {

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

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sat Aug 25 17:10:57 2007
@@ -3195,14 +3195,10 @@
     return DAG.getNode(ISD::FCOPYSIGN, VT, N0, N1);
   
   if (N1CFP) {
+    APFloat V = N1CFP->getValueAPF();
     // copysign(x, c1) -> fabs(x)       iff ispos(c1)
     // copysign(x, c1) -> fneg(fabs(x)) iff isneg(c1)
-    union {
-      double d;
-      int64_t i;
-    } u;
-    u.d = N1CFP->getValue();
-    if (u.i >= 0)
+    if (!V.isNegative())
       return DAG.getNode(ISD::FABS, VT, N0);
     else
       return DAG.getNode(ISD::FNEG, VT, DAG.getNode(ISD::FABS, VT, N0));
@@ -3792,7 +3788,7 @@
       default: assert(0 && "Unknown FP type");
       case MVT::f32:
         if (!AfterLegalize || TLI.isTypeLegal(MVT::i32)) {
-          Tmp = DAG.getConstant(FloatToBits(CFP->getValue()), MVT::i32);
+          Tmp = DAG.getConstant(FloatToBits(CFP->getValueAPF().convertToFloat()), MVT::i32);
           return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
                               ST->getSrcValueOffset(), ST->isVolatile(),
                               ST->getAlignment());
@@ -3800,7 +3796,7 @@
         break;
       case MVT::f64:
         if (!AfterLegalize || TLI.isTypeLegal(MVT::i64)) {
-          Tmp = DAG.getConstant(DoubleToBits(CFP->getValue()), MVT::i64);
+          Tmp = DAG.getConstant(DoubleToBits(CFP->getValueAPF().convertToDouble()), MVT::i64);
           return DAG.getStore(Chain, Tmp, Ptr, ST->getSrcValue(),
                               ST->getSrcValueOffset(), ST->isVolatile(),
                               ST->getAlignment());
@@ -3808,7 +3804,7 @@
           // Many FP stores are not make apparent until after legalize, e.g. for
           // argument passing.  Since this is so common, custom legalize the
           // 64-bit integer store into two 32-bit stores.
-          uint64_t Val = DoubleToBits(CFP->getValue());
+          uint64_t Val = DoubleToBits(CFP->getValueAPF().convertToDouble());
           SDOperand Lo = DAG.getConstant(Val & 0xFFFFFFFF, MVT::i32);
           SDOperand Hi = DAG.getConstant(Val >> 32, MVT::i32);
           if (!TLI.isLittleEndian()) std::swap(Lo, Hi);
@@ -4365,7 +4361,7 @@
   // Check to see if we can simplify the select into an fabs node
   if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1)) {
     // Allow either -0.0 or 0.0
-    if (CFP->getValue() == 0.0) {
+    if (CFP->getValueAPF().isZero()) {
       // select (setg[te] X, +/-0.0), X, fneg(X) -> fabs
       if ((CC == ISD::SETGE || CC == ISD::SETGT) &&
           N0 == N2 && N3.getOpcode() == ISD::FNEG &&

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

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Sat Aug 25 17:10:57 2007
@@ -48,8 +48,8 @@
 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
 /// As such, this method can be used to do an exact bit-for-bit comparison of
 /// two floating point values.
-bool ConstantFPSDNode::isExactlyValue(double V) const {
-  return Value.bitwiseIsEqual(APFloat(V));
+bool ConstantFPSDNode::isExactlyValue(APFloat V) const {
+  return Value.bitwiseIsEqual(V);
 }
 
 //===----------------------------------------------------------------------===//
@@ -669,7 +669,6 @@
   return SDOperand(N, 0);
 }
 
-
 SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT,
                                       bool isTarget) {
   assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!");





More information about the llvm-commits mailing list