WebAssembly: simply assert on SNaN and NaNs with payloads
authorJF Bastien <jfb@google.com>
Tue, 11 Aug 2015 00:49:20 +0000 (00:49 +0000)
committerJF Bastien <jfb@google.com>
Tue, 11 Aug 2015 00:49:20 +0000 (00:49 +0000)
Summary: convertToHexString doesn't represent them correctly at this point in time. This is a follow-up to sunfish's suggestion in D11914.

Subscribers: llvm-commits, sunfish, jfb

Differential Revision: http://reviews.llvm.org/D11925

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@244551 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
test/CodeGen/WebAssembly/immediates.ll

index 35a4be3805de46fe1ae1df4c0119ae85a2db4c8c..1c24e445a92a0981a1d8561cc89afa7208af4509 100644 (file)
@@ -117,10 +117,11 @@ void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) {
       static const size_t BufBytes = 128;
       char buf[BufBytes];
       APFloat FP = MO.getFPImm()->getValueAPF();
-      const APFloat CanonicalNaN = APFloat::getQNaN(FP.getSemantics());
-      if (FP.isNaN() && !FP.bitwiseIsEqual(CanonicalNaN))
-        // WebAssembly only has NaNs that are positive, quiet, without payload.
-        FP = CanonicalNaN;
+      if (FP.isNaN())
+        assert((FP.bitwiseIsEqual(APFloat::getQNaN(FP.getSemantics())) ||
+                FP.bitwiseIsEqual(
+                    APFloat::getQNaN(FP.getSemantics(), /*Negative=*/true))) &&
+               "convertToHexString handles neither SNaN nor NaN payloads");
       // Use C99's hexadecimal floating-point representation.
       auto Written =
           FP.convertToHexString(buf, /*hexDigits=*/0, /*upperCase=*/false,
index f22e294346680cb3418350c4f8ec1a77aef1a46e..1059ffcea30bc4c3574e143b0176090a58833ebd 100644 (file)
@@ -97,7 +97,7 @@ define float @nan_f32() {
 }
 
 ; CHECK-LABEL: negnan_f32:
-; CHECK-NEXT: (setlocal @0 (immediate nan))
+; CHECK-NEXT: (setlocal @0 (immediate -nan))
 ; CHECK-NEXT: (return @0)
 define float @negnan_f32() {
   ret float 0xFFF8000000000000
@@ -153,7 +153,7 @@ define double @nan_f64() {
 }
 
 ; CHECK-LABEL: negnan_f64:
-; CHECK-NEXT: (setlocal @0 (immediate nan))
+; CHECK-NEXT: (setlocal @0 (immediate -nan))
 ; CHECK-NEXT: (return @0)
 define double @negnan_f64() {
   ret double 0xFFF8000000000000