From a61cda01c29700cdf9c70c4f9308b3c3f13db288 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 1 Feb 2004 22:49:04 +0000 Subject: [PATCH] Second half of a fix for PR218 & test/Regression/Assembler/2004-02-01-NegativeZero.llx. Basically we store floating point values as their integral components, instead of relying on the semantics of floating point < to differentiate between values. This is likely to make the map search be faster anyway. llvm-svn: 11064 --- lib/VMCore/Constants.cpp | 47 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 8b108c23354..caeb8cd08e0 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -698,15 +698,54 @@ ConstantInt *ConstantInt::get(const Type *Ty, unsigned char V) { //---- ConstantFP::get() implementation... // -static ValueMap FPConstants; +namespace llvm { + template<> + struct ConstantCreator { + static ConstantFP *create(const Type *Ty, uint64_t V) { + assert(Ty == Type::DoubleTy); + union { + double F; + uint64_t I; + } T; + T.I = V; + return new ConstantFP(Ty, T.F); + } + }; + template<> + struct ConstantCreator { + static ConstantFP *create(const Type *Ty, uint32_t V) { + assert(Ty == Type::FloatTy); + union { + float F; + uint32_t I; + } T; + T.I = V; + return new ConstantFP(Ty, T.F); + } + }; +} + +static ValueMap DoubleConstants; +static ValueMap FloatConstants; ConstantFP *ConstantFP::get(const Type *Ty, double V) { if (Ty == Type::FloatTy) { // Force the value through memory to normalize it. - volatile float Tmp = V; - V = Tmp; + union { + float F; + uint32_t I; + } T; + T.F = (float)V; + return FloatConstants.getOrCreate(Ty, T.I); + } else { + assert(Ty == Type::DoubleTy); + union { + double F; + uint64_t I; + } T; + T.F = V; + return DoubleConstants.getOrCreate(Ty, T.I); } - return FPConstants.getOrCreate(Ty, V); } //---- ConstantArray::get() implementation...