From 1fc3afb76dbed78d255db276381df6036db2ee98 Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Tue, 2 Feb 2016 13:26:16 -0800 Subject: Minor improvement on static BCE analysis. Rationale: Avoid testing initial range if nothing is known. Change-Id: I22646a5fd6e4481245d1a2f57891d2805550489f --- compiler/optimizing/bounds_check_elimination.cc | 41 +++++++++++++------------ 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'compiler/optimizing/bounds_check_elimination.cc') diff --git a/compiler/optimizing/bounds_check_elimination.cc b/compiler/optimizing/bounds_check_elimination.cc index eee6116098..c307522f2b 100644 --- a/compiler/optimizing/bounds_check_elimination.cc +++ b/compiler/optimizing/bounds_check_elimination.cc @@ -1227,27 +1227,28 @@ class BCEVisitor : public HGraphVisitor { InductionVarRange::Value v1; InductionVarRange::Value v2; bool needs_finite_test = false; - induction_range_.GetInductionRange(context, index, &v1, &v2, &needs_finite_test); - do { - if (v1.is_known && (v1.a_constant == 0 || v1.a_constant == 1) && - v2.is_known && (v2.a_constant == 0 || v2.a_constant == 1)) { - DCHECK(v1.a_constant == 1 || v1.instruction == nullptr); - DCHECK(v2.a_constant == 1 || v2.instruction == nullptr); - ValueRange index_range(GetGraph()->GetArena(), - ValueBound(v1.instruction, v1.b_constant), - ValueBound(v2.instruction, v2.b_constant)); - // If analysis reveals a certain OOB, disable dynamic BCE. - if (index_range.GetLower().LessThan(array_range->GetLower()) || - index_range.GetUpper().GreaterThan(array_range->GetUpper())) { - *try_dynamic_bce = false; - return false; - } - // Use analysis for static bce only if loop is finite. - if (!needs_finite_test && index_range.FitsIn(array_range)) { - return true; + if (induction_range_.GetInductionRange(context, index, &v1, &v2, &needs_finite_test)) { + do { + if (v1.is_known && (v1.a_constant == 0 || v1.a_constant == 1) && + v2.is_known && (v2.a_constant == 0 || v2.a_constant == 1)) { + DCHECK(v1.a_constant == 1 || v1.instruction == nullptr); + DCHECK(v2.a_constant == 1 || v2.instruction == nullptr); + ValueRange index_range(GetGraph()->GetArena(), + ValueBound(v1.instruction, v1.b_constant), + ValueBound(v2.instruction, v2.b_constant)); + // If analysis reveals a certain OOB, disable dynamic BCE. + if (index_range.GetLower().LessThan(array_range->GetLower()) || + index_range.GetUpper().GreaterThan(array_range->GetUpper())) { + *try_dynamic_bce = false; + return false; + } + // Use analysis for static bce only if loop is finite. + if (!needs_finite_test && index_range.FitsIn(array_range)) { + return true; + } } - } - } while (induction_range_.RefineOuter(&v1, &v2)); + } while (induction_range_.RefineOuter(&v1, &v2)); + } return false; } -- cgit v1.2.3-59-g8ed1b