diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -2470,6 +2470,20 @@ unsigned AbbrevToUse = 0; if (C->isNullValue()) { Code = bitc::CST_CODE_NULL; + const ConstantFP *CFP = dyn_cast(C); + // PPC_FP128 determines isZero/isNan/isInf using high-order double value + // only. If we write NULL bits directly, we may clear low-order double + // values unexpectedly. + // eg: + // 0xM0000000000000000FFFFFFFFFFFFFFFFF + // => 0xM000000000000000000000000000000000 + if (CFP && CFP->getType()->isPPC_FP128Ty()) { + Code = bitc::CST_CODE_FLOAT; + APInt api = CFP->getValueAPF().bitcastToAPInt(); + const uint64_t *p = api.getRawData(); + Record.push_back(p[0]); + Record.push_back(p[1]); + } } else if (isa(C)) { Code = bitc::CST_CODE_POISON; } else if (isa(C)) { diff --git a/llvm/test/CodeGen/PowerPC/ppc_fp128-bcwriter.ll b/llvm/test/CodeGen/PowerPC/ppc_fp128-bcwriter.ll --- a/llvm/test/CodeGen/PowerPC/ppc_fp128-bcwriter.ll +++ b/llvm/test/CodeGen/PowerPC/ppc_fp128-bcwriter.ll @@ -1,7 +1,7 @@ ; RUN: llvm-as < %s -o - | llvm-dis - | FileCheck %s ;CHECK-LABEL: main -;CHECK: store ppc_fp128 0xM0000000000000000000000000000000 +;CHECK: store ppc_fp128 0xM0000000000000000FFFFFFFFFFFFFFFF define i32 @main() local_unnamed_addr { _main_entry: