Bug 1420894 - Optimize a check in float-to-int conversion. r=lth
authorbobslept <bobslept@protonmail.com>
Wed, 16 May 2018 16:35:42 +0200
changeset 419652 b384ccfe2e50d0a4a0af66514e86b0d61e67a6b3
parent 419651 ddf1909c4e58f2ae2ddbddb8ffc8d035c464cb64
child 419653 1a3b9492f30dd0604966e7b4f322332807ceb55a
push id34041
push userebalazs@mozilla.com
push dateThu, 24 May 2018 09:38:21 +0000
treeherdermozilla-central@043e4ab6e724 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslth
bugs1420894
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1420894 - Optimize a check in float-to-int conversion. r=lth
js/src/jit/arm/MacroAssembler-arm.cpp
--- a/js/src/jit/arm/MacroAssembler-arm.cpp
+++ b/js/src/jit/arm/MacroAssembler-arm.cpp
@@ -5936,35 +5936,24 @@ MacroAssembler::speculationBarrier()
 }
 
 //}}} check_macroassembler_style
 
 void
 MacroAssemblerARM::wasmTruncateToInt32(FloatRegister input, Register output, MIRType fromType,
                                        bool isUnsigned, bool isSaturating, Label* oolEntry)
 {
-    // vcvt* converts NaN into 0, so check for NaNs here.
-    if (!isSaturating) {
-        if (fromType == MIRType::Double)
-            asMasm().compareDouble(input, input);
-        else if (fromType == MIRType::Float32)
-            asMasm().compareFloat(input, input);
-        else
-            MOZ_CRASH("unexpected type in visitWasmTruncateToInt32");
-
-        ma_b(oolEntry, Assembler::VFP_Unordered);
-    }
-
     ScratchDoubleScope scratchScope(asMasm());
     ScratchRegisterScope scratchReg(asMasm());
     FloatRegister scratch = scratchScope.uintOverlay();
 
     // ARM conversion instructions clamp the value to ensure it fits within the
     // target's type bounds, so every time we see those, we need to check the
-    // input.
+    // input. A NaN check is not necessary because NaN is converted to zero and
+    // on a zero result we branch out of line to do further processing anyway.
     if (isUnsigned) {
         if (fromType == MIRType::Double)
             ma_vcvt_F64_U32(input, scratch);
         else if (fromType == MIRType::Float32)
             ma_vcvt_F32_U32(input, scratch);
         else
             MOZ_CRASH("unexpected type in visitWasmTruncateToInt32");
 
@@ -5975,16 +5964,28 @@ MacroAssemblerARM::wasmTruncateToInt32(F
             ma_cmp(output, Imm32(-1), scratchReg);
             as_cmp(output, Imm8(0), Assembler::NotEqual);
             ma_b(oolEntry, Assembler::Equal);
         }
 
         return;
     }
 
+    // vcvt* converts NaN into 0, so check for NaNs here.
+    if (!isSaturating) {
+        if (fromType == MIRType::Double)
+            asMasm().compareDouble(input, input);
+        else if (fromType == MIRType::Float32)
+            asMasm().compareFloat(input, input);
+        else
+            MOZ_CRASH("unexpected type in visitWasmTruncateToInt32");
+
+        ma_b(oolEntry, Assembler::VFP_Unordered);
+    }
+
     scratch = scratchScope.sintOverlay();
 
     if (fromType == MIRType::Double)
         ma_vcvt_F64_I32(input, scratch);
     else if (fromType == MIRType::Float32)
         ma_vcvt_F32_I32(input, scratch);
     else
         MOZ_CRASH("unexpected type in visitWasmTruncateToInt32");