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