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

Side by Side 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: Rename function. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/typer.h" 5 #include "src/compiler/typer.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 8
9 #include "src/base/flags.h" 9 #include "src/base/flags.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 // the increment, just return the initial value's type. 644 // the increment, just return the initial value's type.
645 if (!initial_type->IsInhabited() || !increment_type->IsInhabited()) { 645 if (!initial_type->IsInhabited() || !increment_type->IsInhabited()) {
646 return initial_type; 646 return initial_type;
647 } 647 }
648 648
649 // Now process the bounds. 649 // Now process the bounds.
650 auto res = induction_vars_->induction_variables().find(node->id()); 650 auto res = induction_vars_->induction_variables().find(node->id());
651 DCHECK(res != induction_vars_->induction_variables().end()); 651 DCHECK(res != induction_vars_->induction_variables().end());
652 InductionVariable* induction_var = res->second; 652 InductionVariable* induction_var = res->second;
653 653
654 InductionVariable::ArithmeticType arithmeticType = induction_var->Type();
655
654 double min = -V8_INFINITY; 656 double min = -V8_INFINITY;
655 double max = V8_INFINITY; 657 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.
656 if (increment_type->Min() >= 0) { 658 if ((increment_type->Min() >= 0 &&
659 arithmeticType == InductionVariable::ArithmeticType::kAddition) ||
660 (increment_type->Max() <= 0 &&
661 arithmeticType == InductionVariable::ArithmeticType::kSubtraction)) {
662 // increasing sequence (add positive values, or subtract negative values)
657 min = initial_type->Min(); 663 min = initial_type->Min();
658 for (auto bound : induction_var->upper_bounds()) { 664 for (auto bound : induction_var->upper_bounds()) {
659 Type* bound_type = TypeOrNone(bound.bound); 665 Type* bound_type = TypeOrNone(bound.bound);
660 // If the type is not an integer, just skip the bound. 666 // If the type is not an integer, just skip the bound.
661 if (!bound_type->Is(typer_->cache_.kInteger)) continue; 667 if (!bound_type->Is(typer_->cache_.kInteger)) continue;
662 // If the type is not inhabited, then we can take the initial value. 668 // If the type is not inhabited, then we can take the initial value.
663 if (!bound_type->IsInhabited()) { 669 if (!bound_type->IsInhabited()) {
664 max = initial_type->Max(); 670 max = initial_type->Max();
665 break; 671 break;
666 } 672 }
667 double bound_max = bound_type->Max(); 673 double bound_max = bound_type->Max();
668 if (bound.kind == InductionVariable::kStrict) { 674 if (bound.kind == InductionVariable::kStrict) {
669 bound_max -= 1; 675 bound_max -= 1;
670 } 676 }
671 max = std::min(max, bound_max + increment_type->Max()); 677 double bound_max_next_iteration;
678 if (arithmeticType == InductionVariable::ArithmeticType::kAddition) {
679 // find max, i.e., add the largest positive value
680 bound_max_next_iteration = bound_max + increment_type->Max();
681 } else {
682 // find max, i.e., subtract the smallest negative value
683 bound_max_next_iteration = bound_max - increment_type->Min();
684 }
685 max = std::min(max, bound_max_next_iteration);
672 } 686 }
673 // The upper bound must be at least the initial value's upper bound. 687 // The upper bound must be at least the initial value's upper bound.
674 max = std::max(max, initial_type->Max()); 688 max = std::max(max, initial_type->Max());
675 } else if (increment_type->Max() <= 0) { 689 } else if ((increment_type->Max() <= 0 &&
690 arithmeticType == InductionVariable::ArithmeticType::kAddition) ||
691 (increment_type->Min() >= 0 &&
692 arithmeticType ==
693 InductionVariable::ArithmeticType::kSubtraction)) {
694 // decreasing sequence (add negative values, or subtract positive values)
676 max = initial_type->Max(); 695 max = initial_type->Max();
677 for (auto bound : induction_var->lower_bounds()) { 696 for (auto bound : induction_var->lower_bounds()) {
678 Type* bound_type = TypeOrNone(bound.bound); 697 Type* bound_type = TypeOrNone(bound.bound);
679 // If the type is not an integer, just skip the bound. 698 // If the type is not an integer, just skip the bound.
680 if (!bound_type->Is(typer_->cache_.kInteger)) continue; 699 if (!bound_type->Is(typer_->cache_.kInteger)) continue;
681 // If the type is not inhabited, then we can take the initial value. 700 // If the type is not inhabited, then we can take the initial value.
682 if (!bound_type->IsInhabited()) { 701 if (!bound_type->IsInhabited()) {
683 min = initial_type->Min(); 702 min = initial_type->Min();
684 break; 703 break;
685 } 704 }
686 double bound_min = bound_type->Min(); 705 double bound_min = bound_type->Min();
687 if (bound.kind == InductionVariable::kStrict) { 706 if (bound.kind == InductionVariable::kStrict) {
688 bound_min += 1; 707 bound_min += 1;
689 } 708 }
690 min = std::max(min, bound_min + increment_type->Min()); 709 double bound_min_next_iteration;
710 if (arithmeticType == InductionVariable::ArithmeticType::kAddition) {
711 // find min, i.e., add the smallest negative value
712 bound_min_next_iteration = bound_min + increment_type->Min();
713 } else {
714 // find min, i.e., subtract the largest positive value
715 bound_min_next_iteration = bound_min - increment_type->Max();
716 }
717 min = std::max(min, bound_min_next_iteration);
691 } 718 }
692 // The lower bound must be at most the initial value's lower bound. 719 // The lower bound must be at most the initial value's lower bound.
693 min = std::min(min, initial_type->Min()); 720 min = std::min(min, initial_type->Min());
694 } else { 721 } else {
695 // Shortcut: If the increment can be both positive and negative, 722 // Shortcut: If the increment can be both positive and negative,
696 // the variable can go arbitrarily far, so just return integer. 723 // the variable can go arbitrarily far, so just return integer.
697 return typer_->cache_.kInteger; 724 return typer_->cache_.kInteger;
698 } 725 }
699 if (FLAG_trace_turbo_loop) { 726 if (FLAG_trace_turbo_loop) {
700 OFStream os(stdout); 727 OFStream os(stdout);
701 os << std::setprecision(10); 728 os << std::setprecision(10);
702 os << "Loop (" << NodeProperties::GetControlInput(node)->id() 729 os << "Loop (" << NodeProperties::GetControlInput(node)->id()
703 << ") variable bounds for phi " << node->id() << ": (" << min << ", " 730 << ") variable bounds in "
704 << max << ")\n"; 731 << (arithmeticType == InductionVariable::ArithmeticType::kAddition
732 ? "addition"
733 : "subtraction")
734 << " for phi " << node->id() << ": (" << min << ", " << max << ")\n";
705 } 735 }
706 return Type::Range(min, max, typer_->zone()); 736 return Type::Range(min, max, typer_->zone());
707 } 737 }
708 738
709 Type* Typer::Visitor::TypeEffectPhi(Node* node) { 739 Type* Typer::Visitor::TypeEffectPhi(Node* node) {
710 UNREACHABLE(); 740 UNREACHABLE();
711 return nullptr; 741 return nullptr;
712 } 742 }
713 743
714 Type* Typer::Visitor::TypeLoopExit(Node* node) { 744 Type* Typer::Visitor::TypeLoopExit(Node* node) {
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 } 2351 }
2322 if (Type::IsInteger(*value)) { 2352 if (Type::IsInteger(*value)) {
2323 return Type::Range(value->Number(), value->Number(), zone()); 2353 return Type::Range(value->Number(), value->Number(), zone());
2324 } 2354 }
2325 return Type::Constant(value, zone()); 2355 return Type::Constant(value, zone());
2326 } 2356 }
2327 2357
2328 } // namespace compiler 2358 } // namespace compiler
2329 } // namespace internal 2359 } // namespace internal
2330 } // namespace v8 2360 } // namespace v8
OLDNEW
« src/compiler/loop-variable-optimizer.cc ('K') | « src/compiler/loop-variable-optimizer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698