[llvm] c62dabc - [WebAssembly] Avoid `bit_cast` when printing f32 and f64 immediates

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 26 14:19:43 PST 2021


Author: Dan Gohman
Date: 2021-02-26T14:19:02-08:00
New Revision: c62dabc3f501d3c60846bb6259113990d4f02e75

URL: https://github.com/llvm/llvm-project/commit/c62dabc3f501d3c60846bb6259113990d4f02e75
DIFF: https://github.com/llvm/llvm-project/commit/c62dabc3f501d3c60846bb6259113990d4f02e75.diff

LOG: [WebAssembly] Avoid `bit_cast` when printing f32 and f64 immediates

Use `APInt` to convert a 32-bit or 64-bit immediate to an `APFloat` rather than
`bit_cast` to a `float` or `double` to avoid going through host floating-point and
potentially changing the bit pattern of NaNs.

Differential Revision: https://reviews.llvm.org/D97490

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
index 39b95da94e7c..7e5d81028cb1 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
@@ -281,9 +281,9 @@ void WebAssemblyInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
   } else if (Op.isImm()) {
     O << Op.getImm();
   } else if (Op.isSFPImm()) {
-    O << ::toString(APFloat(bit_cast<float>(Op.getSFPImm())));
+    O << ::toString(APFloat(APFloat::IEEEsingle(), APInt(32, Op.getSFPImm())));
   } else if (Op.isDFPImm()) {
-    O << ::toString(APFloat(bit_cast<double>(Op.getDFPImm())));
+    O << ::toString(APFloat(APFloat::IEEEdouble(), APInt(64, Op.getDFPImm())));
   } else {
     assert(Op.isExpr() && "unknown operand kind in printOperand");
     // call_indirect instructions have a TYPEINDEX operand that we print


        


More information about the llvm-commits mailing list