Bug 1147353 - Odin: simplify the masked index bounds check test. r=sfink, r=luke
authorDouglas Crosher <dtc-moz@scieneer.com>
Thu, 26 Mar 2015 10:04:05 +1100
changeset 266440 7e4aab7d129f8c122885c6e7ba729c56b2245811
parent 266439 9b2d059dffc9313ca582be18bb2ec7a04f6b8dd3
child 266441 f95cac3a56942f284faddc835c49d0a8960b4da4
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink, luke
bugs1147353
milestone39.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 1147353 - Odin: simplify the masked index bounds check test. r=sfink, r=luke
js/src/asmjs/AsmJSValidate.cpp
--- a/js/src/asmjs/AsmJSValidate.cpp
+++ b/js/src/asmjs/AsmJSValidate.cpp
@@ -4438,30 +4438,23 @@ FoldMaskedArrayIndex(FunctionCompiler &f
 {
     MOZ_ASSERT((*indexExpr)->isKind(PNK_BITAND));
 
     ParseNode *indexNode = BitwiseLeft(*indexExpr);
     ParseNode *maskNode = BitwiseRight(*indexExpr);
 
     uint32_t mask2;
     if (IsLiteralOrConstInt(f, maskNode, &mask2)) {
-        // Flag the access to skip the bounds check if the mask ensures that an 'out of
-        // bounds' access can not occur based on the current heap length constraint.
-        if (mask2 == 0) {
+        // Flag the access to skip the bounds check if the mask ensures that an
+        // 'out of bounds' access can not occur based on the current heap length
+        // constraint. The unsigned maximum of a masked index is the mask
+        // itself, so check that the mask is not negative and compare the mask
+        // to the known minimum heap length.
+        if (int32_t(mask2) >= 0 && mask2 < f.m().minHeapLength())
             *needsBoundsCheck = NO_BOUNDS_CHECK;
-        } else {
-            uint32_t minHeap = f.m().minHeapLength();
-            uint32_t minHeapZeroes = CountLeadingZeroes32(minHeap - 1);
-            uint32_t maskZeroes = CountLeadingZeroes32(mask2);
-            if ((minHeapZeroes < maskZeroes) ||
-                (IsPowerOfTwo(minHeap) && minHeapZeroes == maskZeroes))
-            {
-                *needsBoundsCheck = NO_BOUNDS_CHECK;
-            }
-        }
         *mask &= mask2;
         *indexExpr = indexNode;
         return true;
     }
 
     return false;
 }