498 Node* in = n_cl->in(i);
499 if (in == NULL) continue;
500 n_cl->set_req(i, _old_new[in->_idx]);
501 }
502 } else { // process next input
503 _stack.set_index(idx + 1);
504 Node* m = n->in(idx);
505 if (m != NULL && !_clone_visited.test_set(m->_idx)) {
506 clone_visit(m); // visit the input
507 }
508 }
509 }
510 }
511
512 public:
513 Invariance(Arena* area, IdealLoopTree* lpt) :
514 _lpt(lpt), _phase(lpt->_phase),
515 _visited(area), _invariant(area), _stack(area, 10 /* guess */),
516 _clone_visited(area), _old_new(area)
517 {
518 Node* head = _lpt->_head;
519 Node* entry = head->in(LoopNode::EntryControl);
520 if (entry->outcnt() != 1) {
521 // If a node is pinned between the predicates and the loop
522 // entry, we won't be able to move any node in the loop that
523 // depends on it above it in a predicate. Mark all those nodes
524 // as non loop invariatnt.
525 Unique_Node_List wq;
526 wq.push(entry);
527 for (uint next = 0; next < wq.size(); ++next) {
528 Node *n = wq.at(next);
529 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
530 Node* u = n->fast_out(i);
531 if (!u->is_CFG()) {
532 Node* c = _phase->get_ctrl(u);
533 if (_lpt->is_member(_phase->get_loop(c)) || _phase->is_dominator(c, head)) {
534 _visited.set(u->_idx);
535 wq.push(u);
536 }
537 }
538 }
539 }
784 }
785 return bol;
786 }
787
788 //------------------------------ loop_predication_impl--------------------------
789 // Insert loop predicates for null checks and range checks
790 bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree *loop) {
791 if (!UseLoopPredicate) return false;
792
793 if (!loop->_head->is_Loop()) {
794 // Could be a simple region when irreducible loops are present.
795 return false;
796 }
797 LoopNode* head = loop->_head->as_Loop();
798
799 if (head->unique_ctrl_out()->Opcode() == Op_NeverBranch) {
800 // do nothing for infinite loops
801 return false;
802 }
803
804 CountedLoopNode *cl = NULL;
805 if (head->is_valid_counted_loop()) {
806 cl = head->as_CountedLoop();
807 // do nothing for iteration-splitted loops
808 if (!cl->is_normal_loop()) return false;
809 // Avoid RCE if Counted loop's test is '!='.
810 BoolTest::mask bt = cl->loopexit()->test_trip();
811 if (bt != BoolTest::lt && bt != BoolTest::gt)
812 cl = NULL;
813 }
814
815 Node* entry = head->in(LoopNode::EntryControl);
816 ProjNode *predicate_proj = NULL;
817 // Loop limit check predicate should be near the loop.
818 predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
819 if (predicate_proj != NULL)
820 entry = predicate_proj->in(0)->in(0);
821 predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
822 if (!predicate_proj) {
823 #ifndef PRODUCT
824 if (TraceLoopPredicate) {
825 tty->print("missing predicate:");
826 loop->dump_head();
827 head->dump(1);
828 }
829 #endif
830 return false;
831 }
832 ConNode* zero = _igvn.intcon(0);
833 set_ctrl(zero, C->root());
834
835 ResourceArea *area = Thread::current()->resource_area();
989 }
990 assert(new_predicate_proj != NULL, "sanity");
991 // Success - attach condition (new_predicate_bol) to predicate if
992 invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate
993
994 // Eliminate the old If in the loop body
995 dominated_by( new_predicate_proj, iff, proj->_con != new_predicate_proj->_con );
996
997 hoisted = true;
998 C->set_major_progress();
999 } // end while
1000
1001 #ifndef PRODUCT
1002 // report that the loop predication has been actually performed
1003 // for this loop
1004 if (TraceLoopPredicate && hoisted) {
1005 tty->print("Loop Predication Performed:");
1006 loop->dump_head();
1007 }
1008 #endif
1009
1010 return hoisted;
1011 }
1012
1013 //------------------------------loop_predication--------------------------------
1014 // driver routine for loop predication optimization
1015 bool IdealLoopTree::loop_predication( PhaseIdealLoop *phase) {
1016 bool hoisted = false;
1017 // Recursively promote predicates
1018 if (_child) {
1019 hoisted = _child->loop_predication( phase);
1020 }
1021
1022 // self
1023 if (!_irreducible && !tail()->is_top()) {
1024 hoisted |= phase->loop_predication_impl(this);
1025 }
1026
1027 if (_next) { //sibling
1028 hoisted |= _next->loop_predication( phase);
|
498 Node* in = n_cl->in(i);
499 if (in == NULL) continue;
500 n_cl->set_req(i, _old_new[in->_idx]);
501 }
502 } else { // process next input
503 _stack.set_index(idx + 1);
504 Node* m = n->in(idx);
505 if (m != NULL && !_clone_visited.test_set(m->_idx)) {
506 clone_visit(m); // visit the input
507 }
508 }
509 }
510 }
511
512 public:
513 Invariance(Arena* area, IdealLoopTree* lpt) :
514 _lpt(lpt), _phase(lpt->_phase),
515 _visited(area), _invariant(area), _stack(area, 10 /* guess */),
516 _clone_visited(area), _old_new(area)
517 {
518 LoopNode* head = _lpt->_head->as_Loop();
519 Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl);
520 if (entry->outcnt() != 1) {
521 // If a node is pinned between the predicates and the loop
522 // entry, we won't be able to move any node in the loop that
523 // depends on it above it in a predicate. Mark all those nodes
524 // as non loop invariatnt.
525 Unique_Node_List wq;
526 wq.push(entry);
527 for (uint next = 0; next < wq.size(); ++next) {
528 Node *n = wq.at(next);
529 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
530 Node* u = n->fast_out(i);
531 if (!u->is_CFG()) {
532 Node* c = _phase->get_ctrl(u);
533 if (_lpt->is_member(_phase->get_loop(c)) || _phase->is_dominator(c, head)) {
534 _visited.set(u->_idx);
535 wq.push(u);
536 }
537 }
538 }
539 }
784 }
785 return bol;
786 }
787
788 //------------------------------ loop_predication_impl--------------------------
789 // Insert loop predicates for null checks and range checks
790 bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree *loop) {
791 if (!UseLoopPredicate) return false;
792
793 if (!loop->_head->is_Loop()) {
794 // Could be a simple region when irreducible loops are present.
795 return false;
796 }
797 LoopNode* head = loop->_head->as_Loop();
798
799 if (head->unique_ctrl_out()->Opcode() == Op_NeverBranch) {
800 // do nothing for infinite loops
801 return false;
802 }
803
804 if (head->Opcode() == Op_Loop && head->is_strip_mined()) {
805 return false;
806 }
807
808 CountedLoopNode *cl = NULL;
809 if (head->is_valid_counted_loop()) {
810 cl = head->as_CountedLoop();
811 // do nothing for iteration-splitted loops
812 if (!cl->is_normal_loop()) return false;
813 // Avoid RCE if Counted loop's test is '!='.
814 BoolTest::mask bt = cl->loopexit()->test_trip();
815 if (bt != BoolTest::lt && bt != BoolTest::gt)
816 cl = NULL;
817 }
818
819 Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl);
820 ProjNode *predicate_proj = NULL;
821 // Loop limit check predicate should be near the loop.
822 predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
823 if (predicate_proj != NULL)
824 entry = predicate_proj->in(0)->in(0);
825 predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
826 if (!predicate_proj) {
827 #ifndef PRODUCT
828 if (TraceLoopPredicate) {
829 tty->print("missing predicate:");
830 loop->dump_head();
831 head->dump(1);
832 }
833 #endif
834 return false;
835 }
836 ConNode* zero = _igvn.intcon(0);
837 set_ctrl(zero, C->root());
838
839 ResourceArea *area = Thread::current()->resource_area();
993 }
994 assert(new_predicate_proj != NULL, "sanity");
995 // Success - attach condition (new_predicate_bol) to predicate if
996 invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate
997
998 // Eliminate the old If in the loop body
999 dominated_by( new_predicate_proj, iff, proj->_con != new_predicate_proj->_con );
1000
1001 hoisted = true;
1002 C->set_major_progress();
1003 } // end while
1004
1005 #ifndef PRODUCT
1006 // report that the loop predication has been actually performed
1007 // for this loop
1008 if (TraceLoopPredicate && hoisted) {
1009 tty->print("Loop Predication Performed:");
1010 loop->dump_head();
1011 }
1012 #endif
1013
1014 head->verify_strip_mined(1);
1015
1016 return hoisted;
1017 }
1018
1019 //------------------------------loop_predication--------------------------------
1020 // driver routine for loop predication optimization
1021 bool IdealLoopTree::loop_predication( PhaseIdealLoop *phase) {
1022 bool hoisted = false;
1023 // Recursively promote predicates
1024 if (_child) {
1025 hoisted = _child->loop_predication( phase);
1026 }
1027
1028 // self
1029 if (!_irreducible && !tail()->is_top()) {
1030 hoisted |= phase->loop_predication_impl(this);
1031 }
1032
1033 if (_next) { //sibling
1034 hoisted |= _next->loop_predication( phase);
|