From 45afcc26ffa38e6a7d9afddf497a92438dca608f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 2 Jul 2013 10:40:04 -0700 Subject: [PATCH] Bug 866137 - Implement range analysis for LoadTypedArrayElement r=jandem --- js/src/ion/MIR.h | 2 ++ js/src/ion/RangeAnalysis.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/js/src/ion/MIR.h b/js/src/ion/MIR.h index 2c53de252f3..d7bffd30b6b 100644 --- a/js/src/ion/MIR.h +++ b/js/src/ion/MIR.h @@ -4949,6 +4949,8 @@ class MLoadTypedArrayElement AliasSet getAliasSet() const { return AliasSet::Load(AliasSet::TypedArrayElement); } + + void computeRange(); }; // Load a value from a typed array. Out-of-bounds accesses are handled using diff --git a/js/src/ion/RangeAnalysis.cpp b/js/src/ion/RangeAnalysis.cpp index e4527add4dd..348c28af235 100644 --- a/js/src/ion/RangeAnalysis.cpp +++ b/js/src/ion/RangeAnalysis.cpp @@ -769,10 +769,38 @@ MToInt32::computeRange() setRange(new Range(input.lower(), input.upper())); } +static Range *GetTypedArrayRange(int type) +{ + switch (type) { + case TypedArray::TYPE_UINT8_CLAMPED: + case TypedArray::TYPE_UINT8: return new Range(0, UINT8_MAX); + case TypedArray::TYPE_UINT16: return new Range(0, UINT16_MAX); + case TypedArray::TYPE_UINT32: return new Range(0, UINT32_MAX); + + case TypedArray::TYPE_INT8: return new Range(INT8_MIN, INT8_MAX); + case TypedArray::TYPE_INT16: return new Range(INT16_MIN, INT16_MAX); + case TypedArray::TYPE_INT32: return new Range(INT32_MIN, INT32_MAX); + + case TypedArray::TYPE_FLOAT32: + case TypedArray::TYPE_FLOAT64: + break; + } + + return NULL; +} + +void +MLoadTypedArrayElement::computeRange() +{ + if (Range *range = GetTypedArrayRange(arrayType())) + setRange(range); +} + void MLoadTypedArrayElementStatic::computeRange() { - setRange(new Range(this)); + if (Range *range = GetTypedArrayRange(TypedArray::type(typedArray_))) + setRange(range); } ///////////////////////////////////////////////////////////////////////////////