diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 5675c55571..e93d340203 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -947,6 +947,25 @@ void HBoundsCheck::InferRepresentation(HInferRepresentationPhase* h_infer) { } +Range* HBoundsCheck::InferRange(Zone* zone) { + Representation r = representation(); + if (r.IsSmiOrInteger32() && length()->HasRange()) { + int upper = length()->range()->upper() - (allow_equality() ? 0 : 1); + int lower = 0; + + Range* result = new(zone) Range(lower, upper); + if (index()->HasRange()) { + result->Intersect(index()->range()); + } + + // In case of Smi representation, clamp result to Smi::kMaxValue. + if (r.IsSmi()) result->ClampToSmi(); + return result; + } + return HValue::InferRange(zone); +} + + void HBoundsCheckBaseIndexInformation::PrintDataTo(StringStream* stream) { stream->Add("base: "); base_index()->PrintNameTo(stream); diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index eac3c51a3d..272c6bdaf0 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -4029,6 +4029,8 @@ class HBoundsCheck V8_FINAL : public HTemplateInstruction<2> { protected: friend class HBoundsCheckBaseIndexInformation; + virtual Range* InferRange(Zone* zone) V8_OVERRIDE; + virtual bool DataEquals(HValue* other) V8_OVERRIDE { return true; } bool skip_check_; HValue* base_;