Chromium Code Reviews| Index: src/compiler/typer.cc |
| diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc |
| index 37d9a94006ff7a7501fc9bb93bdd81da26215db2..288df95b2f4841b4e96b8416481b394a820a4c34 100644 |
| --- a/src/compiler/typer.cc |
| +++ b/src/compiler/typer.cc |
| @@ -651,9 +651,27 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { |
| DCHECK(res != induction_vars_->induction_variables().end()); |
| InductionVariable* induction_var = res->second; |
| + InductionVariable::ArithmeticType arithmetic_type = induction_var->Type(); |
| + |
| double min = -V8_INFINITY; |
| double max = V8_INFINITY; |
| - if (increment_type->Min() >= 0) { |
| + |
| + double increment_min; |
| + double increment_max; |
| + if (arithmetic_type == InductionVariable::ArithmeticType::kAddition) { |
| + increment_min = increment_type->Min(); |
| + increment_max = increment_type->Max(); |
| + } else { |
| + DCHECK(arithmetic_type == InductionVariable::ArithmeticType::kSubtraction); |
| + increment_min = -increment_type->Max(); |
| + increment_max = -increment_type->Min(); |
| + } |
| + |
| + if ((increment_type->Min() >= 0 && |
| + arithmetic_type == InductionVariable::ArithmeticType::kAddition) || |
| + (increment_type->Max() <= 0 && |
| + arithmetic_type == InductionVariable::ArithmeticType::kSubtraction)) { |
|
Jarin
2016/08/22 07:27:20
How about
if (increment_min >= 0) {
Franzi
2016/08/22 09:06:30
Thanks!
|
| + // increasing sequence (add positive values, or subtract negative values) |
| min = initial_type->Min(); |
| for (auto bound : induction_var->upper_bounds()) { |
| Type* bound_type = TypeOrNone(bound.bound); |
| @@ -668,11 +686,17 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { |
| if (bound.kind == InductionVariable::kStrict) { |
| bound_max -= 1; |
| } |
| - max = std::min(max, bound_max + increment_type->Max()); |
| + max = std::min(max, bound_max + increment_max); |
| } |
| // The upper bound must be at least the initial value's upper bound. |
| max = std::max(max, initial_type->Max()); |
| - } else if (increment_type->Max() <= 0) { |
| + } else if ((increment_type->Max() <= 0 && |
| + arithmetic_type == |
| + InductionVariable::ArithmeticType::kAddition) || |
| + (increment_type->Min() >= 0 && |
| + arithmetic_type == |
| + InductionVariable::ArithmeticType::kSubtraction)) { |
| + // decreasing sequence (add negative values, or subtract positive values) |
|
Jarin
2016/08/22 07:27:19
} else if (increment_max <= 0) {
Franzi
2016/08/22 09:06:30
Done.
|
| max = initial_type->Max(); |
| for (auto bound : induction_var->lower_bounds()) { |
| Type* bound_type = TypeOrNone(bound.bound); |
| @@ -687,7 +711,7 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { |
| if (bound.kind == InductionVariable::kStrict) { |
| bound_min += 1; |
| } |
| - min = std::max(min, bound_min + increment_type->Min()); |
| + min = std::max(min, bound_min + increment_min); |
| } |
| // The lower bound must be at most the initial value's lower bound. |
| min = std::min(min, initial_type->Min()); |
| @@ -700,8 +724,11 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { |
| OFStream os(stdout); |
| os << std::setprecision(10); |
| os << "Loop (" << NodeProperties::GetControlInput(node)->id() |
| - << ") variable bounds for phi " << node->id() << ": (" << min << ", " |
| - << max << ")\n"; |
| + << ") variable bounds in " |
| + << (arithmetic_type == InductionVariable::ArithmeticType::kAddition |
| + ? "addition" |
| + : "subtraction") |
| + << " for phi " << node->id() << ": (" << min << ", " << max << ")\n"; |
| } |
| return Type::Range(min, max, typer_->zone()); |
| } |