Bug 1520162 - Part 2: Fold MMinMax with MTypedArrayLength and same operands. r=jandem
authorAndré Bargull <andre.bargull@gmail.com>
Tue, 15 Jan 2019 06:31:20 -0800
changeset 511632 eeba38937ef453e93a82a04146f06e32f002aba7
parent 511631 689577cc5af1aada96523fcba4ac194ac3061d88
child 511633 44969cba88bf40040c0afa6ebb231525e6df9711
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1520162
milestone66.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 1520162 - Part 2: Fold MMinMax with MTypedArrayLength and same operands. r=jandem
js/src/jit/MIR.cpp
--- a/js/src/jit/MIR.cpp
+++ b/js/src/jit/MIR.cpp
@@ -2956,16 +2956,19 @@ void MMinMax::trySpecializeFloat32(TempA
     return;
   }
 
   specialization_ = MIRType::Float32;
   setResultType(MIRType::Float32);
 }
 
 MDefinition* MMinMax::foldsTo(TempAllocator& alloc) {
+  if (lhs() == rhs()) {
+    return lhs();
+  }
   if (!lhs()->isConstant() && !rhs()->isConstant()) {
     return this;
   }
 
   // Directly apply math utility to compare the rhs() and lhs() when
   // they are both constants.
   if (lhs()->isConstant() && rhs()->isConstant()) {
     if (!lhs()->toConstant()->isTypeRepresentableAsDouble() ||
@@ -3020,23 +3023,25 @@ MDefinition* MMinMax::foldsTo(TempAlloca
       MLimitedTruncate* limit = MLimitedTruncate::New(
           alloc, operand->getOperand(0), MDefinition::NoTruncate);
       block()->insertBefore(this, limit);
       MToDouble* toDouble = MToDouble::New(alloc, limit);
       return toDouble;
     }
   }
 
-  if (operand->isArrayLength() && constant->type() == MIRType::Int32) {
+  if ((operand->isArrayLength() || operand->isTypedArrayLength()) &&
+      constant->type() == MIRType::Int32) {
     MOZ_ASSERT(operand->type() == MIRType::Int32);
 
-    // max(array.length, 0) = array.length
-    // ArrayLength is always >= 0, so just return it.
-    if (isMax() && constant->toInt32() <= 0) {
-      return operand;
+    // (Typed)ArrayLength is always >= 0.
+    // max(array.length, cte <= 0) = array.length
+    // min(array.length, cte <= 0) = cte
+    if (constant->toInt32() <= 0) {
+      return isMax() ? operand : constant;
     }
   }
 
   return this;
 }
 
 MDefinition* MPow::foldsConstant(TempAllocator& alloc) {
   // Both `x` and `p` in `x^p` must be constants in order to precompute.