add some simple hacky long double support for the CBE. This
authorChris Lattner <sabre@nondot.org>
Fri, 17 Oct 2008 06:11:48 +0000 (06:11 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 17 Oct 2008 06:11:48 +0000 (06:11 +0000)
should work for intel long double, but ppc long double aborts
in convert.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57672 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp

index 7ec649d0c52b4beb50617e8bd55463a26b3e5984..72bc920b0325a61d5fcaaa79528054e718d01fda 100644 (file)
@@ -1129,11 +1129,21 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
                        "long double")
           << "*)&FPConstant" << I->second << ')';
     } else {
-      assert(FPC->getType() == Type::FloatTy || 
-             FPC->getType() == Type::DoubleTy);
-      double V = FPC->getType() == Type::FloatTy ? 
-                 FPC->getValueAPF().convertToFloat() : 
-                 FPC->getValueAPF().convertToDouble();
+      double V;
+      if (FPC->getType() == Type::FloatTy)
+        V = FPC->getValueAPF().convertToFloat();
+      else if (FPC->getType() == Type::DoubleTy)
+        V = FPC->getValueAPF().convertToDouble();
+      else {
+        // Long double.  Convert the number to double, discarding precision.
+        // This is not awesome, but it at least makes the CBE output somewhat
+        // useful.
+        APFloat Tmp = FPC->getValueAPF();
+        bool LosesInfo;
+        Tmp.convert(APFloat::IEEEdouble, APFloat::rmTowardZero, &LosesInfo);
+        V = Tmp.convertToDouble();
+      }
+      
       if (IsNAN(V)) {
         // The value is NaN