Skip to content

Commit 7bb9992

Browse files
Tim NorthoverTim Northover
authored andcommitted
Allow the asm printer to print fp128 values properly.
llvm-svn: 171866
1 parent 6e67bed commit 7bb9992

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,27 +1784,30 @@ static void emitGlobalConstantFP(const ConstantFP *CFP, unsigned AddrSpace,
17841784
return;
17851785
}
17861786

1787-
if (CFP->getType()->isX86_FP80Ty()) {
1787+
if (CFP->getType()->isX86_FP80Ty() || CFP->getType()->isFP128Ty()) {
17881788
// all long double variants are printed as hex
17891789
// API needed to prevent premature destruction
17901790
APInt API = CFP->getValueAPF().bitcastToAPInt();
17911791
const uint64_t *p = API.getRawData();
17921792
if (AP.isVerbose()) {
17931793
// Convert to double so we can print the approximate val as a comment.
1794-
APFloat DoubleVal = CFP->getValueAPF();
1795-
bool ignored;
1796-
DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
1797-
&ignored);
1798-
AP.OutStreamer.GetCommentOS() << "x86_fp80 ~= "
1799-
<< DoubleVal.convertToDouble() << '\n';
1794+
SmallString<8> StrVal;
1795+
CFP->getValueAPF().toString(StrVal);
1796+
1797+
const char *TyNote = CFP->getType()->isFP128Ty() ? "fp128 " : "x86_fp80 ";
1798+
AP.OutStreamer.GetCommentOS() << TyNote << StrVal << '\n';
18001799
}
18011800

1801+
// The 80-bit type is made of a 64-bit and 16-bit value, the 128-bit has 2
1802+
// 64-bit words.
1803+
uint32_t TrailingSize = CFP->getType()->isFP128Ty() ? 8 : 2;
1804+
18021805
if (AP.TM.getDataLayout()->isBigEndian()) {
1803-
AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
1806+
AP.OutStreamer.EmitIntValue(p[1], TrailingSize, AddrSpace);
18041807
AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
18051808
} else {
18061809
AP.OutStreamer.EmitIntValue(p[0], 8, AddrSpace);
1807-
AP.OutStreamer.EmitIntValue(p[1], 2, AddrSpace);
1810+
AP.OutStreamer.EmitIntValue(p[1], TrailingSize, AddrSpace);
18081811
}
18091812

18101813
// Emit the tail padding for the long double.

llvm/test/CodeGen/ARM/fp128.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
; RUN: llc -march=arm < %s | FileCheck --check-prefix=LITTLEENDIAN %s
2+
3+
@var = global fp128 0xL00000000000000008000000000000000
4+
5+
; CHECK-LITTLEENDIAN: var:
6+
; CHECK-LITTLEENDIAN-NEXT: .long 0 @ fp128 -0
7+
; CHECK-LITTLEENDIAN-NEXT: .long 0
8+
; CHECK-LITTLEENDIAN-NEXT: .long 0
9+
; CHECK-LITTLEENDIAN-NEXT: .long 2147483648
10+

llvm/test/CodeGen/PowerPC/fp128.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
; RUN: llc -march=ppc64 < %s | FileCheck --check-prefix=BIGENDIAN %s
2+
3+
@var = global fp128 0xL00000000000000008000000000000000
4+
5+
; CHECK-BIGENDIAN: var:
6+
; CHECK-BIGENDIAN-NEXT: .quad -9223372036854775808 # fp128 -0
7+
; CHECK-BIGENDIAN-NEXT: .quad 0
8+

0 commit comments

Comments
 (0)