Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: src/compiler/typer.cc

Issue 2260153002: [turbofan] Induction variable decrement bound analysis. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@DeleteUnusedVar
Patch Set: Simplify if-else loop Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/loop-variable-optimizer.cc ('k') | test/mjsunit/induction-variable-turbofan.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/typer.cc
diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc
index 37d9a94006ff7a7501fc9bb93bdd81da26215db2..5d210b6bee3a3e6d89be73c93ad071489fa132f0 100644
--- a/src/compiler/typer.cc
+++ b/src/compiler/typer.cc
@@ -651,9 +651,24 @@ 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_min >= 0) {
+ // increasing sequence
min = initial_type->Min();
for (auto bound : induction_var->upper_bounds()) {
Type* bound_type = TypeOrNone(bound.bound);
@@ -668,11 +683,12 @@ 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_max <= 0) {
+ // decreasing sequence
max = initial_type->Max();
for (auto bound : induction_var->lower_bounds()) {
Type* bound_type = TypeOrNone(bound.bound);
@@ -687,7 +703,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 +716,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());
}
« no previous file with comments | « src/compiler/loop-variable-optimizer.cc ('k') | test/mjsunit/induction-variable-turbofan.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698