Bug 1147353 - Odin: simplify the masked index bounds check test. r=sfink, r=luke

This commit is contained in:
Douglas Crosher 2015-03-26 10:04:05 +11:00
parent e315209812
commit 32c1fe7bea

View File

@ -4443,20 +4443,13 @@ FoldMaskedArrayIndex(FunctionCompiler &f, ParseNode **indexExpr, int32_t *mask,
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;