Bug 1321189: Don't set instructions that can trap as Movable; r=jandem
authorBenjamin Bouvier <benj@benj.me>
Wed, 30 Nov 2016 11:39:14 +0100
changeset 325261 d2ba2e62f871b632535cf8de373f26da1fe649c1
parent 325260 c8545ffbd0cb18f7ae3a5810f5b98ec0ba8be0e0
child 325262 f3e7734500e0e001f6af7521a3c9784f6bb42996
push id84637
push userbbouvier@mozilla.com
push dateMon, 05 Dec 2016 22:19:07 +0000
treeherdermozilla-inbound@f3e7734500e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1321189
milestone53.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 1321189: Don't set instructions that can trap as Movable; r=jandem
js/src/jit-test/tests/wasm/regress/movable-traps.js
js/src/jit/MIR.h
new file mode 100644
--- /dev/null
+++ b/js/src/jit-test/tests/wasm/regress/movable-traps.js
@@ -0,0 +1,40 @@
+load(libdir + "wasm.js");
+
+let bodies = [
+    `
+    i32.const 1
+    i32.const 0
+    i32.div_s
+    `,
+    `
+    i32.const 1
+    i32.const 0
+    i32.rem_s
+    `,
+    `
+    f64.const 1797693134862315708145274e284
+    i64.trunc_s/f64
+    `,
+    `
+    f32.const 1797693134862315708145274e284
+    i32.trunc_s/f32
+    `
+];
+
+for (let body of bodies) {
+    wasmFullPass(`
+    (module
+        (func $f (param $x i32) (result i32)
+            loop $top
+                get_local $x
+                if
+                    get_local $x
+                    br 2
+                end
+                ${body}
+                br $top
+            end
+        )
+        (export "run" $f)
+    )`, 42, {}, 42);
+}
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -5434,18 +5434,17 @@ class MWasmTruncateToInt64
     wasm::TrapOffset trapOffset_;
 
     MWasmTruncateToInt64(MDefinition* def, bool isUnsigned, wasm::TrapOffset trapOffset)
       : MUnaryInstruction(def),
         isUnsigned_(isUnsigned),
         trapOffset_(trapOffset)
     {
         setResultType(MIRType::Int64);
-        setGuard(); // not removable because of possible side-effects.
-        setMovable();
+        setGuard(); // neither removable nor movable because of possible side-effects.
     }
 
   public:
     INSTRUCTION_HEADER(WasmTruncateToInt64)
     TRIVIAL_NEW_WRAPPERS
 
     bool isUnsigned() const { return isUnsigned_; }
     wasm::TrapOffset trapOffset() const { return trapOffset_; }
@@ -5467,18 +5466,17 @@ class MWasmTruncateToInt32
 {
     bool isUnsigned_;
     wasm::TrapOffset trapOffset_;
 
     explicit MWasmTruncateToInt32(MDefinition* def, bool isUnsigned, wasm::TrapOffset trapOffset)
       : MUnaryInstruction(def), isUnsigned_(isUnsigned), trapOffset_(trapOffset)
     {
         setResultType(MIRType::Int32);
-        setGuard(); // not removable because of possible side-effects.
-        setMovable();
+        setGuard(); // neither removable nor movable because of possible side-effects.
     }
 
   public:
     INSTRUCTION_HEADER(WasmTruncateToInt32)
     TRIVIAL_NEW_WRAPPERS
 
     bool isUnsigned() const {
         return isUnsigned_;
@@ -7027,18 +7025,20 @@ class MDiv : public MBinaryArithInstruct
                      MIRType type, bool unsignd, bool trapOnError = false,
                      wasm::TrapOffset trapOffset = wasm::TrapOffset(),
                      bool mustPreserveNaN = false)
     {
         auto* div = new(alloc) MDiv(left, right, type);
         div->unsigned_ = unsignd;
         div->trapOnError_ = trapOnError;
         div->trapOffset_ = trapOffset;
-        if (trapOnError)
+        if (trapOnError) {
             div->setGuard(); // not removable because of possible side-effects.
+            div->setNotMovable();
+        }
         div->setMustPreserveNaN(mustPreserveNaN);
         if (type == MIRType::Int32)
             div->setTruncateKind(Truncate);
         return div;
     }
 
     MDefinition* foldsTo(TempAllocator& alloc) override;
     void analyzeEdgeCasesForward() override;
@@ -7161,18 +7161,20 @@ class MMod : public MBinaryArithInstruct
     static MMod* New(TempAllocator& alloc, MDefinition* left, MDefinition* right,
                      MIRType type, bool unsignd, bool trapOnError = false,
                      wasm::TrapOffset trapOffset = wasm::TrapOffset())
     {
         auto* mod = new(alloc) MMod(left, right, type);
         mod->unsigned_ = unsignd;
         mod->trapOnError_ = trapOnError;
         mod->trapOffset_ = trapOffset;
-        if (trapOnError)
+        if (trapOnError) {
             mod->setGuard(); // not removable because of possible side-effects.
+            mod->setNotMovable();
+        }
         if (type == MIRType::Int32)
             mod->setTruncateKind(Truncate);
         return mod;
     }
 
     MDefinition* foldsTo(TempAllocator& alloc) override;
 
     double getIdentity() override {