Bug 1627618 - Part 7: Set MBinaryArithInstruction specialisation in the constructor. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 07 Apr 2020 09:12:42 +0000
changeset 522635 f37a78d235334c76a30bfb208f79646bc434027e
parent 522634 45396902c72426c9f4cd35e055c8e4c517aff45b
child 522636 e14f372e1c71b9fad8dd9f36d2cf4d49556707d1
push id37293
push userapavel@mozilla.com
push dateTue, 07 Apr 2020 21:44:02 +0000
treeherdermozilla-central@de63e64b9090 [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 7: Set MBinaryArithInstruction specialisation in the constructor. r=jandem Set the specialisation and the return type directly in `MBinaryArithInstruction`. Also assert that the specialisation is definitely a number type. Differential Revision: https://phabricator.services.mozilla.com/D69787
js/src/jit/MIR.cpp
js/src/jit/MIR.h
--- a/js/src/jit/MIR.cpp
+++ b/js/src/jit/MIR.cpp
@@ -2784,17 +2784,16 @@ void MBinaryArithInstruction::printOpcod
 }
 #endif
 
 MBinaryArithInstruction* MBinaryArithInstruction::New(TempAllocator& alloc,
                                                       Opcode op,
                                                       MDefinition* left,
                                                       MDefinition* right,
                                                       MIRType specialization) {
-  MOZ_ASSERT(IsNumberType(specialization));
   switch (op) {
     case Opcode::Add:
       return MAdd::New(alloc, left, right, specialization);
     case Opcode::Sub:
       return MSub::New(alloc, left, right, specialization);
     case Opcode::Mul:
       return MMul::New(alloc, left, right, specialization);
     case Opcode::Div:
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -4774,21 +4774,24 @@ class MBinaryArithInstruction : public M
   TruncateKind implicitTruncate_;
 
   // Whether we must preserve NaN semantics, and in particular not fold
   // (x op id) or (id op x) to x, or replace a division by a multiply of the
   // exact reciprocal.
   bool mustPreserveNaN_;
 
  public:
-  MBinaryArithInstruction(Opcode op, MDefinition* left, MDefinition* right)
+  MBinaryArithInstruction(Opcode op, MDefinition* left, MDefinition* right,
+                          MIRType type)
       : MBinaryInstruction(op, left, right),
         implicitTruncate_(NoTruncate),
         mustPreserveNaN_(false) {
-    specialization_ = MIRType::None;
+    MOZ_ASSERT(IsNumberType(type));
+    specialization_ = type;
+    setResultType(type);
     setMovable();
   }
 
   static MBinaryArithInstruction* New(TempAllocator& alloc, Opcode op,
                                       MDefinition* left, MDefinition* right,
                                       MIRType specialization);
 
   bool constantDoubleResult(TempAllocator& alloc);
@@ -4799,23 +4802,20 @@ class MBinaryArithInstruction : public M
   MDefinition* foldsTo(TempAllocator& alloc) override;
 #ifdef JS_JITSPEW
   void printOpcode(GenericPrinter& out) const override;
 #endif
 
   virtual double getIdentity() = 0;
 
   void setSpecialization(MIRType type) {
+    MOZ_ASSERT(IsNumberType(type));
     specialization_ = type;
     setResultType(type);
   }
-  void setInt32Specialization() {
-    specialization_ = MIRType::Int32;
-    setResultType(MIRType::Int32);
-  }
 
   virtual void trySpecializeFloat32(TempAllocator& alloc) override;
 
   bool congruentTo(const MDefinition* ins) const override {
     if (!binaryCongruentTo(ins)) {
       return false;
     }
     const auto* other = static_cast<const MBinaryArithInstruction*>(ins);
@@ -5348,20 +5348,17 @@ class MMathFunction : public MUnaryInstr
     }
   }
 
   ALLOW_CLONE(MMathFunction)
 };
 
 class MAdd : public MBinaryArithInstruction {
   MAdd(MDefinition* left, MDefinition* right, MIRType type)
-      : MBinaryArithInstruction(classOpcode, left, right) {
-    specialization_ = type;
-    setResultType(type);
-  }
+      : MBinaryArithInstruction(classOpcode, left, right, type) {}
 
   MAdd(MDefinition* left, MDefinition* right, TruncateKind truncateKind)
       : MAdd(left, right, MIRType::Int32) {
     setTruncateKind(truncateKind);
     setCommutative();
   }
 
  public:
@@ -5394,20 +5391,17 @@ class MAdd : public MBinaryArithInstruct
     return specialization_ < MIRType::Object;
   }
 
   ALLOW_CLONE(MAdd)
 };
 
 class MSub : public MBinaryArithInstruction {
   MSub(MDefinition* left, MDefinition* right, MIRType type)
-      : MBinaryArithInstruction(classOpcode, left, right) {
-    specialization_ = type;
-    setResultType(type);
-  }
+      : MBinaryArithInstruction(classOpcode, left, right, type) {}
 
  public:
   INSTRUCTION_HEADER(Sub)
   TRIVIAL_NEW_WRAPPERS
 
   static MSub* NewWasm(TempAllocator& alloc, MDefinition* left,
                        MDefinition* right, MIRType type, bool mustPreserveNaN) {
     auto* ret = new (alloc) MSub(left, right, type);
@@ -5444,30 +5438,27 @@ class MMul : public MBinaryArithInstruct
  private:
   // Annotation the result could be a negative zero
   // and we need to guard this during execution.
   bool canBeNegativeZero_;
 
   Mode mode_;
 
   MMul(MDefinition* left, MDefinition* right, MIRType type, Mode mode)
-      : MBinaryArithInstruction(classOpcode, left, right),
+      : MBinaryArithInstruction(classOpcode, left, right, type),
         canBeNegativeZero_(true),
         mode_(mode) {
     if (mode == Integer) {
       // This implements the required behavior for Math.imul, which
       // can never fail and always truncates its output to int32.
       canBeNegativeZero_ = false;
       setTruncateKind(Truncate);
       setCommutative();
     }
     MOZ_ASSERT_IF(mode != Integer, mode == Normal);
-
-    specialization_ = type;
-    setResultType(type);
   }
 
  public:
   INSTRUCTION_HEADER(Mul)
 
   static MMul* New(TempAllocator& alloc, MDefinition* left, MDefinition* right,
                    MIRType type, Mode mode = Normal) {
     return new (alloc) MMul(left, right, type, mode);
@@ -5544,26 +5535,23 @@ class MDiv : public MBinaryArithInstruct
   bool canBeNegativeOverflow_;
   bool canBeDivideByZero_;
   bool canBeNegativeDividend_;
   bool unsigned_;  // If false, signedness will be derived from operands
   bool trapOnError_;
   wasm::BytecodeOffset bytecodeOffset_;
 
   MDiv(MDefinition* left, MDefinition* right, MIRType type)
-      : MBinaryArithInstruction(classOpcode, left, right),
+      : MBinaryArithInstruction(classOpcode, left, right, type),
         canBeNegativeZero_(true),
         canBeNegativeOverflow_(true),
         canBeDivideByZero_(true),
         canBeNegativeDividend_(true),
         unsigned_(false),
-        trapOnError_(false) {
-    specialization_ = type;
-    setResultType(type);
-  }
+        trapOnError_(false) {}
 
  public:
   INSTRUCTION_HEADER(Div)
 
   static MDiv* New(TempAllocator& alloc, MDefinition* left, MDefinition* right,
                    MIRType type) {
     return new (alloc) MDiv(left, right, type);
   }
@@ -5667,25 +5655,22 @@ class MMod : public MBinaryArithInstruct
   bool unsigned_;  // If false, signedness will be derived from operands
   bool canBeNegativeDividend_;
   bool canBePowerOfTwoDivisor_;
   bool canBeDivideByZero_;
   bool trapOnError_;
   wasm::BytecodeOffset bytecodeOffset_;
 
   MMod(MDefinition* left, MDefinition* right, MIRType type)
-      : MBinaryArithInstruction(classOpcode, left, right),
+      : MBinaryArithInstruction(classOpcode, left, right, type),
         unsigned_(false),
         canBeNegativeDividend_(true),
         canBePowerOfTwoDivisor_(true),
         canBeDivideByZero_(true),
-        trapOnError_(false) {
-    specialization_ = type;
-    setResultType(type);
-  }
+        trapOnError_(false) {}
 
  public:
   INSTRUCTION_HEADER(Mod)
 
   static MMod* New(TempAllocator& alloc, MDefinition* left, MDefinition* right,
                    MIRType type) {
     return new (alloc) MMod(left, right, type);
   }