746
747 // Negate test if necessary
748 bool negated = false;
749 if (proj->_con != predicate_proj->_con) {
750 new_predicate_bol = new BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate());
751 register_new_node(new_predicate_bol, ctrl);
752 negated = true;
753 }
754 IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If();
755 _igvn.hash_delete(new_predicate_iff);
756 new_predicate_iff->set_req(1, new_predicate_bol);
757 #ifndef PRODUCT
758 if (TraceLoopPredicate) {
759 tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx);
760 loop->dump_head();
761 } else if (TraceLoopOpts) {
762 tty->print("Predicate IC ");
763 loop->dump_head();
764 }
765 #endif
766 } else if ((cl != NULL) && (proj->_con == predicate_proj->_con) &&
767 loop->is_range_check_if(iff, this, invar)) {
768
769 // Range check for counted loops
770 const Node* cmp = bol->in(1)->as_Cmp();
771 Node* idx = cmp->in(1);
772 assert(!invar.is_invariant(idx), "index is variant");
773 Node* rng = cmp->in(2);
774 assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be");
775 assert(invar.is_invariant(rng), "range must be invariant");
776 int scale = 1;
777 Node* offset = zero;
778 bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset);
779 assert(ok, "must be index expression");
780
781 Node* init = cl->init_trip();
782 Node* limit = cl->limit();
783 Node* stride = cl->stride();
784
785 // Build if's for the upper and lower bound tests. The
786 // lower_bound test will dominate the upper bound test and all
787 // cloned or created nodes will use the lower bound test as
788 // their declared control.
789 ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
790 ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
791 assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate");
792 Node *ctrl = lower_bound_proj->in(0)->as_If()->in(0);
793
794 // Perform cloning to keep Invariance state correct since the
795 // late schedule will place invariant things in the loop.
796 rng = invar.clone(rng, ctrl);
797 if (offset && offset != zero) {
798 assert(invar.is_invariant(offset), "offset must be loop invariant");
799 offset = invar.clone(offset, ctrl);
800 }
801
802 // Test the lower bound
803 Node* lower_bound_bol = rc_predicate(loop, ctrl, scale, offset, init, limit, stride, rng, false);
804 IfNode* lower_bound_iff = lower_bound_proj->in(0)->as_If();
805 _igvn.hash_delete(lower_bound_iff);
806 lower_bound_iff->set_req(1, lower_bound_bol);
807 if (TraceLoopPredicate) tty->print_cr("lower bound check if: %d", lower_bound_iff->_idx);
808
809 // Test the upper bound
810 Node* upper_bound_bol = rc_predicate(loop, lower_bound_proj, scale, offset, init, limit, stride, rng, true);
811 IfNode* upper_bound_iff = upper_bound_proj->in(0)->as_If();
812 _igvn.hash_delete(upper_bound_iff);
813 upper_bound_iff->set_req(1, upper_bound_bol);
814 if (TraceLoopPredicate) tty->print_cr("upper bound check if: %d", lower_bound_iff->_idx);
815
816 // Fall through into rest of the clean up code which will move
817 // any dependent nodes onto the upper bound test.
818 new_predicate_proj = upper_bound_proj;
819
820 #ifndef PRODUCT
821 if (TraceLoopOpts && !TraceLoopPredicate) {
822 tty->print("Predicate RC ");
823 loop->dump_head();
824 }
825 #endif
826 } else {
827 // Loop variant check (for example, range check in non-counted loop)
828 // with uncommon trap.
829 continue;
830 }
831 assert(new_predicate_proj != NULL, "sanity");
832 // Success - attach condition (new_predicate_bol) to predicate if
833 invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate
834
|
746
747 // Negate test if necessary
748 bool negated = false;
749 if (proj->_con != predicate_proj->_con) {
750 new_predicate_bol = new BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate());
751 register_new_node(new_predicate_bol, ctrl);
752 negated = true;
753 }
754 IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If();
755 _igvn.hash_delete(new_predicate_iff);
756 new_predicate_iff->set_req(1, new_predicate_bol);
757 #ifndef PRODUCT
758 if (TraceLoopPredicate) {
759 tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx);
760 loop->dump_head();
761 } else if (TraceLoopOpts) {
762 tty->print("Predicate IC ");
763 loop->dump_head();
764 }
765 #endif
766 } else if (cl != NULL && loop->is_range_check_if(iff, this, invar)) {
767 // Range check for counted loops
768 const Node* cmp = bol->in(1)->as_Cmp();
769 Node* idx = cmp->in(1);
770 assert(!invar.is_invariant(idx), "index is variant");
771 Node* rng = cmp->in(2);
772 assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be");
773 assert(invar.is_invariant(rng), "range must be invariant");
774 int scale = 1;
775 Node* offset = zero;
776 bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset);
777 assert(ok, "must be index expression");
778
779 Node* init = cl->init_trip();
780 Node* limit = cl->limit();
781 Node* stride = cl->stride();
782
783 // Build if's for the upper and lower bound tests. The
784 // lower_bound test will dominate the upper bound test and all
785 // cloned or created nodes will use the lower bound test as
786 // their declared control.
787 ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
788 ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
789 assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate");
790 Node *ctrl = lower_bound_proj->in(0)->as_If()->in(0);
791
792 // Perform cloning to keep Invariance state correct since the
793 // late schedule will place invariant things in the loop.
794 rng = invar.clone(rng, ctrl);
795 if (offset && offset != zero) {
796 assert(invar.is_invariant(offset), "offset must be loop invariant");
797 offset = invar.clone(offset, ctrl);
798 }
799
800 // Test the lower bound
801 BoolNode* lower_bound_bol = rc_predicate(loop, ctrl, scale, offset, init, limit, stride, rng, false);
802 // Negate test if necessary
803 bool negated = false;
804 if (proj->_con != predicate_proj->_con) {
805 lower_bound_bol = new BoolNode(lower_bound_bol->in(1), lower_bound_bol->_test.negate());
806 register_new_node(lower_bound_bol, ctrl);
807 negated = true;
808 }
809 IfNode* lower_bound_iff = lower_bound_proj->in(0)->as_If();
810 _igvn.hash_delete(lower_bound_iff);
811 lower_bound_iff->set_req(1, lower_bound_bol);
812 if (TraceLoopPredicate) tty->print_cr("lower bound check if: %s %d ", negated ? " negated" : "", lower_bound_iff->_idx);
813
814 // Test the upper bound
815 BoolNode* upper_bound_bol = rc_predicate(loop, lower_bound_proj, scale, offset, init, limit, stride, rng, true);
816 negated = false;
817 if (proj->_con != predicate_proj->_con) {
818 upper_bound_bol = new BoolNode(upper_bound_bol->in(1), upper_bound_bol->_test.negate());
819 register_new_node(upper_bound_bol, ctrl);
820 negated = true;
821 }
822 IfNode* upper_bound_iff = upper_bound_proj->in(0)->as_If();
823 _igvn.hash_delete(upper_bound_iff);
824 upper_bound_iff->set_req(1, upper_bound_bol);
825 if (TraceLoopPredicate) tty->print_cr("upper bound check if: %s %d ", negated ? " negated" : "", lower_bound_iff->_idx);
826
827 // Fall through into rest of the clean up code which will move
828 // any dependent nodes onto the upper bound test.
829 new_predicate_proj = upper_bound_proj;
830
831 #ifndef PRODUCT
832 if (TraceLoopOpts && !TraceLoopPredicate) {
833 tty->print("Predicate RC ");
834 loop->dump_head();
835 }
836 #endif
837 } else {
838 // Loop variant check (for example, range check in non-counted loop)
839 // with uncommon trap.
840 continue;
841 }
842 assert(new_predicate_proj != NULL, "sanity");
843 // Success - attach condition (new_predicate_bol) to predicate if
844 invar.map_ctrl(proj, new_predicate_proj); // so that invariance test can be appropriate
845
|