Bug 1627618 - Part 2: Add MAdd::NewWasm for MAdd users in wasm code. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 07 Apr 2020 08:35:07 +0000
changeset 522647 b801d8007636e2a979eb1c93dcb82e20fe468ba2
parent 522646 43db59ebd874bf2dcbddd9d6feb0319ccf1a9e70
child 522648 bd3e77b5b2e935b1a371f363e159187cf0fd5c1c
push id112239
push userccoroiu@mozilla.com
push dateTue, 07 Apr 2020 15:04:11 +0000
treeherderautoland@5b653e25e757 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1627618
milestone77.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 1627618 - Part 2: Add MAdd::NewWasm for MAdd users in wasm code. r=jandem Add `MAdd::NewWasm` similar to how we have a separate `MMul:NewWasm` function. For wasm we want to default to `MDefinition::Truncate` and set the "commutative" flag for Int32 values. This frees up the `MAdd(MDefinition, MDefinition, MIRType)` to only set the specialisation and the return type, which will be required for later patches to work correctly. Differential Revision: https://phabricator.services.mozilla.com/D69779
js/src/jit/MIR.h
js/src/wasm/WasmIonCompile.cpp
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -5351,38 +5351,42 @@ class MMathFunction : public MUnaryInstr
 };
 
 class MAdd : public MBinaryArithInstruction {
   MAdd(MDefinition* left, MDefinition* right)
       : MBinaryArithInstruction(classOpcode, left, right) {
     setResultType(MIRType::Value);
   }
 
-  MAdd(MDefinition* left, MDefinition* right, MIRType type,
-       TruncateKind truncateKind = Truncate)
+  MAdd(MDefinition* left, MDefinition* right, MIRType type)
       : MAdd(left, right) {
     specialization_ = type;
     setResultType(type);
-    if (type == MIRType::Int32) {
-      setTruncateKind(truncateKind);
-      setCommutative();
-    }
+  }
 
   MAdd(MDefinition* left, MDefinition* right, TruncateKind truncateKind)
-      : MAdd(left, right) {
-    specialization_ = MIRType::Int32;
-    setResultType(MIRType::Int32);
+      : MAdd(left, right, MIRType::Int32) {
     setTruncateKind(truncateKind);
     setCommutative();
   }
 
  public:
   INSTRUCTION_HEADER(Add)
   TRIVIAL_NEW_WRAPPERS
 
+  static MAdd* NewWasm(TempAllocator& alloc, MDefinition* left,
+                       MDefinition* right, MIRType type) {
+    auto* ret = new (alloc) MAdd(left, right, type);
+    if (type == MIRType::Int32) {
+      ret->setTruncateKind(Truncate);
+      ret->setCommutative();
+    }
+    return ret;
+  }
+
   bool isFloat32Commutative() const override { return true; }
 
   double getIdentity() override { return 0; }
 
   bool fallible() const;
   void computeRange(TempAllocator& alloc) override;
   bool needTruncation(TruncateKind kind) override;
   void truncate() override;
--- a/js/src/wasm/WasmIonCompile.cpp
+++ b/js/src/wasm/WasmIonCompile.cpp
@@ -335,16 +335,25 @@ class FunctionCompiler {
     if (inDeadCode()) {
       return nullptr;
     }
     T* ins = T::New(alloc(), lhs, rhs, type);
     curBlock_->add(ins);
     return ins;
   }
 
+  MDefinition* add(MDefinition* lhs, MDefinition* rhs, MIRType type) {
+    if (inDeadCode()) {
+      return nullptr;
+    }
+    auto* ins = MAdd::NewWasm(alloc(), lhs, rhs, type);
+    curBlock_->add(ins);
+    return ins;
+  }
+
   bool mustPreserveNaN(MIRType type) {
     return IsFloatingPointType(type) && !env().isAsmJS();
   }
 
   MDefinition* sub(MDefinition* lhs, MDefinition* rhs, MIRType type) {
     if (inDeadCode()) {
       return nullptr;
     }
@@ -2518,17 +2527,17 @@ static bool EmitReinterpret(FunctionComp
 
 static bool EmitAdd(FunctionCompiler& f, ValType type, MIRType mirType) {
   MDefinition* lhs;
   MDefinition* rhs;
   if (!f.iter().readBinary(type, &lhs, &rhs)) {
     return false;
   }
 
-  f.iter().setResult(f.binary<MAdd>(lhs, rhs, mirType));
+  f.iter().setResult(f.add(lhs, rhs, mirType));
   return true;
 }
 
 static bool EmitSub(FunctionCompiler& f, ValType type, MIRType mirType) {
   MDefinition* lhs;
   MDefinition* rhs;
   if (!f.iter().readBinary(type, &lhs, &rhs)) {
     return false;