Culling out use of unions for converting FP to bits and vice versa.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22838 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index ab07030..2c01982 100644
--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -975,23 +975,17 @@
// Turn 'store float 1.0, Ptr' -> 'store int 0x12345678, Ptr'
if (ConstantFPSDNode *CFP =dyn_cast<ConstantFPSDNode>(Node->getOperand(1))){
if (CFP->getValueType(0) == MVT::f32) {
- union {
- unsigned I;
- float F;
- } V;
- V.F = CFP->getValue();
Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1,
- DAG.getConstant(V.I, MVT::i32), Tmp2,
+ DAG.getConstant(FloatToBits(CFP->getValue()),
+ MVT::i32),
+ Tmp2,
Node->getOperand(3));
} else {
assert(CFP->getValueType(0) == MVT::f64 && "Unknown FP type!");
- union {
- uint64_t I;
- double F;
- } V;
- V.F = CFP->getValue();
Result = DAG.getNode(ISD::STORE, MVT::Other, Tmp1,
- DAG.getConstant(V.I, MVT::i64), Tmp2,
+ DAG.getConstant(DoubleToBits(CFP->getValue()),
+ MVT::i64),
+ Tmp2,
Node->getOperand(3));
}
Node = Result.Val;
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 6afa9d0..81b0803 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -224,12 +224,8 @@
N->getValueType(0)));
break;
case ISD::ConstantFP: {
- union {
- double DV;
- uint64_t IV;
- };
- DV = cast<ConstantFPSDNode>(N)->getValue();
- ConstantFPs.erase(std::make_pair(IV, N->getValueType(0)));
+ uint64_t V = DoubleToBits(cast<ConstantFPSDNode>(N)->getValue());
+ ConstantFPs.erase(std::make_pair(V, N->getValueType(0)));
break;
}
case ISD::CONDCODE:
@@ -385,14 +381,7 @@
// 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)];
+ SDNode *&N = ConstantFPs[std::make_pair(DoubleToBits(Val), VT)];
if (N) return SDOperand(N, 0);
N = new ConstantFPSDNode(Val, VT);
AllNodes.push_back(N);