[PATCH] D103634: [BitcodeWriter][PowerPC] Avoid clearing lower bits for NullValues

Jinsong Ji via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 3 10:45:07 PDT 2021


jsji created this revision.
jsji added reviewers: PowerPC, qiucf, shchenz.
Herald added subscribers: kbarton, hiraditya, nemanjai.
jsji requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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
======================================

In opt, we may promote complex double into ppc_fp128, so if we clear
the low-order double values, we may change the values of complex
unexpectedly.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103634

Files:
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/test/CodeGen/PowerPC/ppc_fp128-bcwriter.ll


Index: llvm/test/CodeGen/PowerPC/ppc_fp128-bcwriter.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/ppc_fp128-bcwriter.ll
+++ 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:
Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ 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<ConstantFP>(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<PoisonValue>(C)) {
       Code = bitc::CST_CODE_POISON;
     } else if (isa<UndefValue>(C)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103634.349606.patch
Type: text/x-patch
Size: 1568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210603/36a7db95/attachment.bin>


More information about the llvm-commits mailing list