Bug 1627618 - Part 1: Add MAdd with truncate parameter. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 07 Apr 2020 08:35:25 +0000
changeset 522646 43db59ebd874bf2dcbddd9d6feb0319ccf1a9e70
parent 522645 93389243902532138a05b46222a5f599bb61a4ea
child 522647 b801d8007636e2a979eb1c93dcb82e20fe468ba2
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 1: Add MAdd with truncate parameter. r=jandem Later patches will require a constructor with the signature `MAdd(MDefinition, MDefinition, MIRType)`, which neither sets the truncation mode nor sets the "commutative" flag. Both things happen with the existing constructor which has a compatible signature and which is currently called for the use sites modified in this patch. (The existing constructor is the one directly appearing before the newly added one.) The existing constructor defaults to `MDefinition::Truncate` and all callers to that constructor use the `MIRType::Int32` specialisation. Because all callers use `MIRType::Int32`, we can omit the type parameter for the new constructor. The existing constructor is also called from WasmIonCompile, the next part will handle that caller. Differential Revision: https://phabricator.services.mozilla.com/D69778
js/src/jit/AlignmentMaskAnalysis.cpp
js/src/jit/FoldLinearArithConstants.cpp
js/src/jit/IonBuilder.cpp
js/src/jit/MIR.h
js/src/jit/WarpBuilder.cpp
--- a/js/src/jit/AlignmentMaskAnalysis.cpp
+++ b/js/src/jit/AlignmentMaskAnalysis.cpp
@@ -64,17 +64,17 @@ static void AnalyzeAsmHeapAddress(MDefin
   uint32_t m = rhs->toConstant()->toInt32();
   if (!IsAlignmentMask(m) || (i & m) != i) {
     return;
   }
 
   // The pattern was matched! Produce the replacement expression.
   MInstruction* and_ = MBitAnd::New(graph.alloc(), op0, rhs, MIRType::Int32);
   ptr->block()->insertBefore(ptr->toBitAnd(), and_);
-  MInstruction* add = MAdd::New(graph.alloc(), and_, op1, MIRType::Int32);
+  auto* add = MAdd::New(graph.alloc(), and_, op1, MDefinition::Truncate);
   ptr->block()->insertBefore(ptr->toBitAnd(), add);
   ptr->replaceAllUsesWith(add);
   ptr->block()->discard(ptr->toBitAnd());
 }
 
 bool AlignmentMaskAnalysis::analyze() {
   for (ReversePostorderIterator block(graph_.rpoBegin());
        block != graph_.rpoEnd(); block++) {
--- a/js/src/jit/FoldLinearArithConstants.cpp
+++ b/js/src/jit/FoldLinearArithConstants.cpp
@@ -64,18 +64,17 @@ static void AnalyzeAdd(TempAllocator& al
         sum.constant == add->getOperand(idx)->toConstant()->toInt32()) {
       return;
     }
   }
 
   MInstruction* rhs = MConstant::New(alloc, Int32Value(sum.constant));
   add->block()->insertBefore(add, rhs);
 
-  MAdd* addNew =
-      MAdd::New(alloc, sum.term, rhs, MIRType::Int32, add->truncateKind());
+  MAdd* addNew = MAdd::New(alloc, sum.term, rhs, add->truncateKind());
 
   add->replaceAllLiveUsesWith(addNew);
   add->block()->insertBefore(add, addNew);
   JitSpew(JitSpew_FLAC, "replaced with: %s%u", addNew->opName(), addNew->id());
   JitSpew(JitSpew_FLAC, "and constant: %s%u (%d)", rhs->opName(), rhs->id(),
           sum.constant);
 
   // Mark the stale nodes as RecoveredOnBailout since the Sink pass has
--- a/js/src/jit/IonBuilder.cpp
+++ b/js/src/jit/IonBuilder.cpp
@@ -6976,17 +6976,17 @@ AbortReasonOr<Ok> IonBuilder::jsop_inite
   return resumeAfter(initElem);
 }
 
 AbortReasonOr<Ok> IonBuilder::jsop_initelem_inc() {
   MDefinition* value = current->pop();
   MDefinition* id = current->pop();
   MDefinition* obj = current->peek(-1);
 
-  MAdd* nextId = MAdd::New(alloc(), id, constantInt(1), MIRType::Int32);
+  MAdd* nextId = MAdd::New(alloc(), id, constantInt(1), MDefinition::Truncate);
   current->add(nextId);
   current->push(nextId);
 
   return initArrayElement(obj, id, value);
 }
 
 AbortReasonOr<Ok> IonBuilder::initArrayElement(MDefinition* obj,
                                                MDefinition* id,
--- a/js/src/jit/MIR.h
+++ b/js/src/jit/MIR.h
@@ -5360,16 +5360,23 @@ class MAdd : public MBinaryArithInstruct
        TruncateKind truncateKind = Truncate)
       : 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);
+    setTruncateKind(truncateKind);
+    setCommutative();
   }
 
  public:
   INSTRUCTION_HEADER(Add)
   TRIVIAL_NEW_WRAPPERS
 
   bool isFloat32Commutative() const override { return true; }
 
--- a/js/src/jit/WarpBuilder.cpp
+++ b/js/src/jit/WarpBuilder.cpp
@@ -2469,17 +2469,17 @@ bool WarpBuilder::build_InitElemArray(By
 
 bool WarpBuilder::build_InitElemInc(BytecodeLocation loc) {
   MDefinition* val = current->pop();
   MDefinition* index = current->pop();
   MDefinition* obj = current->peek(-1);
 
   // Push index + 1.
   MConstant* constOne = constant(Int32Value(1));
-  MAdd* nextIndex = MAdd::New(alloc(), index, constOne, MIRType::Int32);
+  MAdd* nextIndex = MAdd::New(alloc(), index, constOne, MDefinition::Truncate);
   current->add(nextIndex);
   current->push(nextIndex);
 
   return buildInitPropOp(loc, obj, index, val);
 }
 
 static LambdaFunctionInfo LambdaInfoFromSnapshot(JSFunction* fun,
                                                  const WarpLambda* snapshot) {