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

Dan Gohman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 25 11:17:13 PST 2021


sunfish created this revision.
Herald added subscribers: ecnelises, hiraditya, jgravelle-google, sbc100, dschuff.
sunfish requested review of this revision.
Herald added a subscriber: aheejin.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D97490

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


Index: llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
+++ llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
@@ -287,9 +287,9 @@
   } 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97490.326448.patch
Type: text/x-patch
Size: 865 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210225/6334e593/attachment.bin>


More information about the llvm-commits mailing list