From 22af3bee34d0ab1a4bd186c71ccab00366882259 Mon Sep 17 00:00:00 2001 From: Aart Bik Date: Thu, 10 Sep 2015 12:50:58 -0700 Subject: Use induction variable range analysis in BCE (statically). Rationale: Finally! After lots of very large CLs, now a small CL that uses the new induction variable analysis in BCE (statically, using this dynamically with de-opt is TBD). Despite its relative small size, be aware though, since the CL introduces a new phase to the compiler. Change-Id: If5555a173fd5d55d147c63138ef51fc296fa1414 --- compiler/optimizing/induction_var_range.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'compiler/optimizing/induction_var_range.cc') diff --git a/compiler/optimizing/induction_var_range.cc b/compiler/optimizing/induction_var_range.cc index bd903340ad..486e904bd1 100644 --- a/compiler/optimizing/induction_var_range.cc +++ b/compiler/optimizing/induction_var_range.cc @@ -126,6 +126,7 @@ HInductionVarAnalysis::InductionInfo* InductionVarRange::GetTripCount(HLoopInfor } InductionVarRange::Value InductionVarRange::GetFetch(HInstruction* instruction, + HInductionVarAnalysis::InductionInfo* trip, int32_t fail_value) { // Detect constants and chase the fetch a bit deeper into the HIR tree, so that it becomes // more likely range analysis will compare the same instructions as terminal nodes. @@ -134,9 +135,16 @@ InductionVarRange::Value InductionVarRange::GetFetch(HInstruction* instruction, return Value(value); } else if (instruction->IsAdd()) { if (IsIntAndGet(instruction->InputAt(0), &value)) { - return AddValue(Value(value), GetFetch(instruction->InputAt(1), fail_value), fail_value); + return AddValue(Value(value), + GetFetch(instruction->InputAt(1), trip, fail_value), fail_value); } else if (IsIntAndGet(instruction->InputAt(1), &value)) { - return AddValue(GetFetch(instruction->InputAt(0), fail_value), Value(value), fail_value); + return AddValue(GetFetch(instruction->InputAt(0), trip, fail_value), + Value(value), fail_value); + } + } else if (fail_value < 0) { + // Special case: within the loop-body, minimum of trip-count is 1. + if (trip != nullptr && instruction == trip->op_b->fetch) { + return Value(1); } } return Value(instruction, 1, 0); @@ -163,7 +171,7 @@ InductionVarRange::Value InductionVarRange::GetMin(HInductionVarAnalysis::Induct case HInductionVarAnalysis::kDiv: return GetDiv(info->op_a, info->op_b, trip, INT_MIN); case HInductionVarAnalysis::kFetch: - return GetFetch(info->fetch, INT_MIN); + return GetFetch(info->fetch, trip, INT_MIN); } break; case HInductionVarAnalysis::kLinear: @@ -200,7 +208,7 @@ InductionVarRange::Value InductionVarRange::GetMax(HInductionVarAnalysis::Induct case HInductionVarAnalysis::kDiv: return GetDiv(info->op_a, info->op_b, trip, INT_MAX); case HInductionVarAnalysis::kFetch: - return GetFetch(info->fetch, INT_MAX); + return GetFetch(info->fetch, trip, INT_MAX); } break; case HInductionVarAnalysis::kLinear: -- cgit v1.2.3-59-g8ed1b