Chromium Code Reviews| Index: src/compiler/typer.cc |
| diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc |
| index 37d9a94006ff7a7501fc9bb93bdd81da26215db2..6e2d4b1d50f07579f76ffedf3a60d4959a3e9b71 100644 |
| --- a/src/compiler/typer.cc |
| +++ b/src/compiler/typer.cc |
| @@ -651,9 +651,15 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { |
| DCHECK(res != induction_vars_->induction_variables().end()); |
| InductionVariable* induction_var = res->second; |
| + InductionVariable::ArithmeticType arithmeticType = induction_var->Type(); |
| + |
| double min = -V8_INFINITY; |
| double max = V8_INFINITY; |
|
Jarin
2016/08/19 13:08:25
Could not you just say here:
double increment_min
Franzi
2016/08/19 18:38:51
Done.
|
| - if (increment_type->Min() >= 0) { |
| + if ((increment_type->Min() >= 0 && |
| + arithmeticType == InductionVariable::ArithmeticType::kAddition) || |
| + (increment_type->Max() <= 0 && |
| + arithmeticType == InductionVariable::ArithmeticType::kSubtraction)) { |
| + // 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 +674,24 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { |
| if (bound.kind == InductionVariable::kStrict) { |
| bound_max -= 1; |
| } |
| - max = std::min(max, bound_max + increment_type->Max()); |
| + double bound_max_next_iteration; |
| + if (arithmeticType == InductionVariable::ArithmeticType::kAddition) { |
| + // find max, i.e., add the largest positive value |
| + bound_max_next_iteration = bound_max + increment_type->Max(); |
| + } else { |
| + // find max, i.e., subtract the smallest negative value |
| + bound_max_next_iteration = bound_max - increment_type->Min(); |
| + } |
| + max = std::min(max, bound_max_next_iteration); |
| } |
| // 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 && |
| + arithmeticType == InductionVariable::ArithmeticType::kAddition) || |
| + (increment_type->Min() >= 0 && |
| + arithmeticType == |
| + InductionVariable::ArithmeticType::kSubtraction)) { |
| + // decreasing sequence (add negative values, or subtract positive values) |
| max = initial_type->Max(); |
| for (auto bound : induction_var->lower_bounds()) { |
| Type* bound_type = TypeOrNone(bound.bound); |
| @@ -687,7 +706,15 @@ Type* Typer::Visitor::TypeInductionVariablePhi(Node* node) { |
| if (bound.kind == InductionVariable::kStrict) { |
| bound_min += 1; |
| } |
| - min = std::max(min, bound_min + increment_type->Min()); |
| + double bound_min_next_iteration; |
| + if (arithmeticType == InductionVariable::ArithmeticType::kAddition) { |
| + // find min, i.e., add the smallest negative value |
| + bound_min_next_iteration = bound_min + increment_type->Min(); |
| + } else { |
| + // find min, i.e., subtract the largest positive value |
| + bound_min_next_iteration = bound_min - increment_type->Max(); |
| + } |
| + min = std::max(min, bound_min_next_iteration); |
| } |
| // The lower bound must be at most the initial value's lower bound. |
| min = std::min(min, initial_type->Min()); |
| @@ -700,8 +727,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 " |
| + << (arithmeticType == InductionVariable::ArithmeticType::kAddition |
| + ? "addition" |
| + : "subtraction") |
| + << " for phi " << node->id() << ": (" << min << ", " << max << ")\n"; |
| } |
| return Type::Range(min, max, typer_->zone()); |
| } |