Allow the asm printer to print fp128 values properly.
authorTim Northover <Tim.Northover@arm.com>
Tue, 8 Jan 2013 16:56:23 +0000 (16:56 +0000)
committerTim Northover <Tim.Northover@arm.com>
Tue, 8 Jan 2013 16:56:23 +0000 (16:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171866 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
test/CodeGen/ARM/fp128.ll [new file with mode: 0644]
test/CodeGen/PowerPC/fp128.ll [new file with mode: 0644]

index 9e43524ad015289d834483669841501ac9081e0f..aa64698644a53a92747241326b965eaa00976cb6 100644 (file)
@@ -1784,27 +1784,30 @@ static void emitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
     return;
   }
 
-  if (CFP->getType()->isX86_FP80Ty()) {
+  if (CFP->getType()->isX86_FP80Ty() || CFP->getType()->isFP128Ty()) {
     // all long double variants are printed as hex
     // API needed to prevent premature destruction
     APInt API = CFP->getValueAPF().bitcastToAPInt();
     const uint64_t *p = API.getRawData();
     if (AP.isVerbose()) {
       // Convert to double so we can print the approximate val as a comment.
-      APFloat DoubleVal = CFP->getValueAPF();
-      bool ignored;
-      DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
-                        &ignored);
-      AP.OutStreamer.GetCommentOS() << "x86_fp80 ~= "
-        << DoubleVal.convertToDouble() << '\n';
+      SmallString<8> StrVal;
+      CFP->getValueAPF().toString(StrVal);
+
+      const char *TyNote = CFP->getType()->isFP128Ty() ? "fp128 " : "x86_fp80 ";
+      AP.OutStreamer.GetCommentOS() << TyNote << StrVal << '\n';
     }
 
+    // The 80-bit type is made of a 64-bit and 16-bit value, the 128-bit has 2
+    // 64-bit words.
+    uint32_t TrailingSize = CFP->getType()->isFP128Ty() ? 8 : 2;
+
     if (AP.TM.getDataLayout()->isBigEndian()) {
-      AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
+      AP.OutStreamer.EmitIntValue(p[1], TrailingSize, AddrSpace);
       AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
     } else {
       AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
-      AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
+      AP.OutStreamer.EmitIntValue(p[1], TrailingSize, AddrSpace);
     }
 
     // Emit the tail padding for the long double.
diff --git a/test/CodeGen/ARM/fp128.ll b/test/CodeGen/ARM/fp128.ll
new file mode 100644 (file)
index 0000000..ab476d4
--- /dev/null
@@ -0,0 +1,10 @@
+; RUN: llc -march=arm < %s | FileCheck --check-prefix=LITTLEENDIAN %s
+
+@var = global fp128 0xL00000000000000008000000000000000
+
+; CHECK-LITTLEENDIAN: var:
+; CHECK-LITTLEENDIAN-NEXT: .long   0                       @ fp128 -0
+; CHECK-LITTLEENDIAN-NEXT: .long   0
+; CHECK-LITTLEENDIAN-NEXT: .long   0
+; CHECK-LITTLEENDIAN-NEXT: .long   2147483648
+
diff --git a/test/CodeGen/PowerPC/fp128.ll b/test/CodeGen/PowerPC/fp128.ll
new file mode 100644 (file)
index 0000000..9755f9b
--- /dev/null
@@ -0,0 +1,8 @@
+; RUN: llc -march=ppc64 < %s | FileCheck --check-prefix=BIGENDIAN %s
+
+@var = global fp128 0xL00000000000000008000000000000000
+
+; CHECK-BIGENDIAN: var:
+; CHECK-BIGENDIAN-NEXT: .quad   -9223372036854775808    # fp128 -0
+; CHECK-BIGENDIAN-NEXT: .quad   0
+