[llvm-commits] CVS: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Feb 17 12:17:45 PST 2005
Changes in directory llvm/lib/CodeGen/SelectionDAG:
SelectionDAG.cpp updated: 1.50 -> 1.51
---
Log message:
Don't rely on doubles comparing identical to each other, which doesn't work
for 0.0 and -0.0.
---
Diffs of the changes: (+19 -4)
SelectionDAG.cpp | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff -u llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.50 llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.51
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1.50 Sat Jan 22 22:39:44 2005
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp Thu Feb 17 14:17:32 2005
@@ -196,10 +196,15 @@
Constants.erase(std::make_pair(cast<ConstantSDNode>(N)->getValue(),
N->getValueType(0)));
break;
- case ISD::ConstantFP:
- ConstantFPs.erase(std::make_pair(cast<ConstantFPSDNode>(N)->getValue(),
- N->getValueType(0)));
+ case ISD::ConstantFP: {
+ union {
+ double DV;
+ uint64_t IV;
+ };
+ DV = cast<ConstantFPSDNode>(N)->getValue();
+ ConstantFPs.erase(std::make_pair(IV, N->getValueType(0)));
break;
+ }
case ISD::GlobalAddress:
GlobalValues.erase(cast<GlobalAddressSDNode>(N)->getGlobal());
break;
@@ -299,7 +304,17 @@
if (VT == MVT::f32)
Val = (float)Val; // Mask out extra precision.
- SDNode *&N = ConstantFPs[std::make_pair(Val, VT)];
+ // 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.
+ union {
+ double DV;
+ uint64_t IV;
+ };
+
+ DV = Val;
+
+ SDNode *&N = ConstantFPs[std::make_pair(IV, VT)];
if (N) return SDOperand(N, 0);
N = new ConstantFPSDNode(Val, VT);
AllNodes.push_back(N);
More information about the llvm-commits
mailing list