[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp

Chris Lattner lattner at cs.uiuc.edu
Sun Feb 1 16:50:01 PST 2004


Changes in directory llvm/lib/VMCore:

Constants.cpp updated: 1.72 -> 1.73

---
Log message:

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.


---
Diffs of the changes:  (+43 -4)

Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.72 llvm/lib/VMCore/Constants.cpp:1.73
--- llvm/lib/VMCore/Constants.cpp:1.72	Thu Jan 22 18:55:21 2004
+++ llvm/lib/VMCore/Constants.cpp	Sun Feb  1 16:49:04 2004
@@ -698,15 +698,54 @@
 
 //---- ConstantFP::get() implementation...
 //
-static ValueMap<double, Type, ConstantFP> FPConstants;
+namespace llvm {
+  template<>
+  struct ConstantCreator<ConstantFP, Type, uint64_t> {
+    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<ConstantFP, Type, uint32_t> {
+    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<uint64_t, Type, ConstantFP> DoubleConstants;
+static ValueMap<uint32_t, Type, ConstantFP> 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...





More information about the llvm-commits mailing list