diff options
author | Jim Laskey <jlaskey@mac.com> | 2005-08-17 19:34:49 +0000 |
---|---|---|
committer | Jim Laskey <jlaskey@mac.com> | 2005-08-17 19:34:49 +0000 |
commit | b74c66618677ec27bc749c70b61d9b723c2e51c5 (patch) | |
tree | aa4a194f382cf242fd704399685090e7b8aca85c /llvm/lib/CodeGen | |
parent | c6aa80668e67972e9c8d4b4a3cdfc285def7c246 (diff) | |
download | bcm5719-llvm-b74c66618677ec27bc749c70b61d9b723c2e51c5.tar.gz bcm5719-llvm-b74c66618677ec27bc749c70b61d9b723c2e51c5.zip |
Culling out use of unions for converting FP to bits and vice versa.
llvm-svn: 22838
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter.cpp | 25 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 18 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 17 |
3 files changed, 16 insertions, 44 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter.cpp index 497e9c89fab..d907d67b5a2 100644 --- a/llvm/lib/CodeGen/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter.cpp @@ -15,6 +15,7 @@ #include "llvm/Constants.h" #include "llvm/Instruction.h" #include "llvm/Support/Mangler.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetMachine.h" using namespace llvm; @@ -222,39 +223,27 @@ void AsmPrinter::emitGlobalConstant(const Constant *CV) { // precision... double Val = CFP->getValue(); if (CFP->getType() == Type::DoubleTy) { - union DU { // Abide by C TBAA rules - double FVal; - uint64_t UVal; - } U; - U.FVal = Val; - if (Data64bitsDirective) - O << Data64bitsDirective << U.UVal << "\t" << CommentString + O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString << " double value: " << Val << "\n"; else if (TD.isBigEndian()) { - O << Data32bitsDirective << unsigned(U.UVal >> 32) + O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32) << "\t" << CommentString << " double most significant word " << Val << "\n"; - O << Data32bitsDirective << unsigned(U.UVal) + O << Data32bitsDirective << unsigned(DoubleToBits(Val)) << "\t" << CommentString << " double least significant word " << Val << "\n"; } else { - O << Data32bitsDirective << unsigned(U.UVal) + O << Data32bitsDirective << unsigned(DoubleToBits(Val)) << "\t" << CommentString << " double least significant word " << Val << "\n"; - O << Data32bitsDirective << unsigned(U.UVal >> 32) + O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32) << "\t" << CommentString << " double most significant word " << Val << "\n"; } return; } else { - union FU { // Abide by C TBAA rules - float FVal; - int32_t UVal; - } U; - U.FVal = (float)Val; - - O << Data32bitsDirective << U.UVal << "\t" << CommentString + O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString << " float " << Val << "\n"; return; } diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index ab070301b08..2c01982df2b 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -975,23 +975,17 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { // 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/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 6afa9d08947..81b08039a47 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -224,12 +224,8 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { 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 @@ SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType 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)]; + SDNode *&N = ConstantFPs[std::make_pair(DoubleToBits(Val), VT)]; if (N) return SDOperand(N, 0); N = new ConstantFPSDNode(Val, VT); AllNodes.push_back(N); |