Skip to content

Commit c62dabc

Browse files
committed
[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
1 parent cafb6cd commit c62dabc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ void WebAssemblyInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
281281
} else if (Op.isImm()) {
282282
O << Op.getImm();
283283
} else if (Op.isSFPImm()) {
284-
O << ::toString(APFloat(bit_cast<float>(Op.getSFPImm())));
284+
O << ::toString(APFloat(APFloat::IEEEsingle(), APInt(32, Op.getSFPImm())));
285285
} else if (Op.isDFPImm()) {
286-
O << ::toString(APFloat(bit_cast<double>(Op.getDFPImm())));
286+
O << ::toString(APFloat(APFloat::IEEEdouble(), APInt(64, Op.getDFPImm())));
287287
} else {
288288
assert(Op.isExpr() && "unknown operand kind in printOperand");
289289
// call_indirect instructions have a TYPEINDEX operand that we print

0 commit comments

Comments
 (0)