[PATCH] D11925: WebAssembly: simply assert on SNaN and NaNs with payloads

JF Bastien via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 10 17:49:08 PDT 2015


jfb created this revision.
jfb added subscribers: sunfish, llvm-commits.
Herald added a subscriber: jfb.

convertToHexString doesn't represent them correctly at this point in time. This is a follow-up to sunfish's suggestion in D11914.

http://reviews.llvm.org/D11925

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

Index: test/CodeGen/WebAssembly/immediates.ll
===================================================================
--- test/CodeGen/WebAssembly/immediates.ll
+++ test/CodeGen/WebAssembly/immediates.ll
@@ -97,7 +97,7 @@
 }
 
 ; 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 @@
 }
 
 ; 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
Index: lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -117,10 +117,11 @@
       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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11925.31753.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150811/3e5f7982/attachment.bin>


More information about the llvm-commits mailing list