diff options
author | 2016-02-02 13:26:16 -0800 | |
---|---|---|
committer | 2016-02-03 09:22:27 -0800 | |
commit | 1fc3afb76dbed78d255db276381df6036db2ee98 (patch) | |
tree | 61ee6429e39fad5ae5d5d6d620966ce90fead39c /compiler/optimizing | |
parent | 97f4bc04b61d5cf78b0820dbf18e999b20d7a108 (diff) |
Minor improvement on static BCE analysis.
Rationale:
Avoid testing initial range if nothing is known.
Change-Id: I22646a5fd6e4481245d1a2f57891d2805550489f
Diffstat (limited to 'compiler/optimizing')
-rw-r--r-- | compiler/optimizing/bounds_check_elimination.cc | 41 | ||||
-rw-r--r-- | compiler/optimizing/induction_var_range.cc | 9 | ||||
-rw-r--r-- | compiler/optimizing/induction_var_range.h | 32 |
3 files changed, 40 insertions, 42 deletions
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; } diff --git a/compiler/optimizing/induction_var_range.cc b/compiler/optimizing/induction_var_range.cc index ae15fcf381..9566c29adf 100644 --- a/compiler/optimizing/induction_var_range.cc +++ b/compiler/optimizing/induction_var_range.cc @@ -93,7 +93,7 @@ InductionVarRange::InductionVarRange(HInductionVarAnalysis* induction_analysis) DCHECK(induction_analysis != nullptr); } -void InductionVarRange::GetInductionRange(HInstruction* context, +bool InductionVarRange::GetInductionRange(HInstruction* context, HInstruction* instruction, /*out*/Value* min_val, /*out*/Value* max_val, @@ -111,12 +111,9 @@ void InductionVarRange::GetInductionRange(HInstruction* context, *min_val = GetVal(info, trip, in_body, /* is_min */ true); *max_val = SimplifyMax(GetVal(info, trip, in_body, /* is_min */ false)); *needs_finite_test = NeedsTripCount(info) && IsUnsafeTripCount(trip); - } else { - // No loop to analyze. - *min_val = Value(); - *max_val = Value(); - *needs_finite_test = false; + return true; } + return false; // Nothing known } bool InductionVarRange::RefineOuter(/*in-out*/Value* min_val, /*in-out*/Value* max_val) const { diff --git a/compiler/optimizing/induction_var_range.h b/compiler/optimizing/induction_var_range.h index 974b8fba06..3cb7b4bfd5 100644 --- a/compiler/optimizing/induction_var_range.h +++ b/compiler/optimizing/induction_var_range.h @@ -60,13 +60,13 @@ class InductionVarRange { * Given a context denoted by the first instruction, returns a possibly conservative * lower and upper bound on the instruction's value in the output parameters min_val * and max_val, respectively. The need_finite_test flag denotes if an additional finite-test - * is needed to protect the range evaluation inside its loop. + * is needed to protect the range evaluation inside its loop. Returns false on failure. */ - void GetInductionRange(HInstruction* context, + bool GetInductionRange(HInstruction* context, HInstruction* instruction, - /*out*/Value* min_val, - /*out*/Value* max_val, - /*out*/bool* needs_finite_test); + /*out*/ Value* min_val, + /*out*/ Value* max_val, + /*out*/ bool* needs_finite_test); /** Refines the values with induction of next outer loop. Returns true on change. */ bool RefineOuter(/*in-out*/Value* min_val, /*in-out*/Value* max_val) const; @@ -79,8 +79,8 @@ class InductionVarRange { */ bool CanGenerateCode(HInstruction* context, HInstruction* instruction, - /*out*/bool* needs_finite_test, - /*out*/bool* needs_taken_test); + /*out*/ bool* needs_finite_test, + /*out*/ bool* needs_taken_test); /** * Generates the actual code in the HIR for the lower and upper bound expressions on the @@ -101,8 +101,8 @@ class InductionVarRange { HInstruction* instruction, HGraph* graph, HBasicBlock* block, - /*out*/HInstruction** lower, - /*out*/HInstruction** upper); + /*out*/ HInstruction** lower, + /*out*/ HInstruction** upper); /** * Generates explicit taken-test for the loop in the given context. Code is generated in @@ -113,7 +113,7 @@ class InductionVarRange { void GenerateTakenTest(HInstruction* context, HGraph* graph, HBasicBlock* block, - /*out*/HInstruction** taken_test); + /*out*/ HInstruction** taken_test); private: bool NeedsTripCount(HInductionVarAnalysis::InductionInfo* info) const; @@ -168,17 +168,17 @@ class InductionVarRange { HInstruction* instruction, HGraph* graph, HBasicBlock* block, - /*out*/HInstruction** lower, - /*out*/HInstruction** upper, - /*out*/HInstruction** taken_test, - /*out*/bool* needs_finite_test, - /*out*/bool* needs_taken_test) const; + /*out*/ HInstruction** lower, + /*out*/ HInstruction** upper, + /*out*/ HInstruction** taken_test, + /*out*/ bool* needs_finite_test, + /*out*/ bool* needs_taken_test) const; bool GenerateCode(HInductionVarAnalysis::InductionInfo* info, HInductionVarAnalysis::InductionInfo* trip, HGraph* graph, HBasicBlock* block, - /*out*/HInstruction** result, + /*out*/ HInstruction** result, bool in_body, bool is_min) const; |