src/share/vm/opto/loopPredicate.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 7009361 Sdiff src/share/vm/opto

src/share/vm/opto/loopPredicate.cpp

Print this page




 683 
 684 //------------------------------rc_predicate-----------------------------------
 685 // Create a range check predicate
 686 //
 687 // for (i = init; i < limit; i += stride) {
 688 //    a[scale*i+offset]
 689 // }
 690 //
 691 // Compute max(scale*i + offset) for init <= i < limit and build the predicate
 692 // as "max(scale*i + offset) u< a.length".
 693 //
 694 // There are two cases for max(scale*i + offset):
 695 // (1) stride*scale > 0
 696 //   max(scale*i + offset) = scale*(limit-stride) + offset
 697 // (2) stride*scale < 0
 698 //   max(scale*i + offset) = scale*init + offset
 699 BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl,
 700                                        int scale, Node* offset,
 701                                        Node* init, Node* limit, Node* stride,
 702                                        Node* range, bool upper) {
 703   DEBUG_ONLY(ttyLocker ttyl);
 704   if (TraceLoopPredicate) tty->print("rc_predicate ");



 705 
 706   Node* max_idx_expr  = init;
 707   int stride_con = stride->get_int();
 708   if ((stride_con > 0) == (scale > 0) == upper) {
 709     max_idx_expr = new (C, 3) SubINode(limit, stride);
 710     register_new_node(max_idx_expr, ctrl);
 711     if (TraceLoopPredicate) tty->print("(limit - stride) ");
 712   } else {
 713     if (TraceLoopPredicate) tty->print("init ");
 714   }
 715 
 716   if (scale != 1) {
 717     ConNode* con_scale = _igvn.intcon(scale);
 718     max_idx_expr = new (C, 3) MulINode(max_idx_expr, con_scale);
 719     register_new_node(max_idx_expr, ctrl);
 720     if (TraceLoopPredicate) tty->print("* %d ", scale);
 721   }
 722 
 723   if (offset && (!offset->is_Con() || offset->get_int() != 0)){
 724     max_idx_expr = new (C, 3) AddINode(max_idx_expr, offset);
 725     register_new_node(max_idx_expr, ctrl);
 726     if (TraceLoopPredicate)
 727       if (offset->is_Con()) tty->print("+ %d ", offset->get_int());
 728       else tty->print("+ offset ");
 729   }
 730 
 731   CmpUNode* cmp = new (C, 3) CmpUNode(max_idx_expr, range);
 732   register_new_node(cmp, ctrl);
 733   BoolNode* bol = new (C, 2) BoolNode(cmp, BoolTest::lt);
 734   register_new_node(bol, ctrl);
 735 
 736   if (TraceLoopPredicate) tty->print_cr("<u range");



 737   return bol;
 738 }
 739 
 740 //------------------------------ loop_predication_impl--------------------------
 741 // Insert loop predicates for null checks and range checks
 742 bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree *loop) {
 743   if (!UseLoopPredicate) return false;
 744 
 745   if (!loop->_head->is_Loop()) {
 746     // Could be a simple region when irreducible loops are present.
 747     return false;
 748   }
 749 
 750   if (loop->_head->unique_ctrl_out()->Opcode() == Op_NeverBranch) {
 751     // do nothing for infinite loops
 752     return false;
 753   }
 754 
 755   CountedLoopNode *cl = NULL;
 756   if (loop->_head->is_CountedLoop()) {




 683 
 684 //------------------------------rc_predicate-----------------------------------
 685 // Create a range check predicate
 686 //
 687 // for (i = init; i < limit; i += stride) {
 688 //    a[scale*i+offset]
 689 // }
 690 //
 691 // Compute max(scale*i + offset) for init <= i < limit and build the predicate
 692 // as "max(scale*i + offset) u< a.length".
 693 //
 694 // There are two cases for max(scale*i + offset):
 695 // (1) stride*scale > 0
 696 //   max(scale*i + offset) = scale*(limit-stride) + offset
 697 // (2) stride*scale < 0
 698 //   max(scale*i + offset) = scale*init + offset
 699 BoolNode* PhaseIdealLoop::rc_predicate(Node* ctrl,
 700                                        int scale, Node* offset,
 701                                        Node* init, Node* limit, Node* stride,
 702                                        Node* range, bool upper) {
 703   stringStream* predString = NULL;
 704   if (TraceLoopPredicate) {
 705     predString = new stringStream();
 706     predString->print("rc_predicate ");
 707   }
 708 
 709   Node* max_idx_expr  = init;
 710   int stride_con = stride->get_int();
 711   if ((stride_con > 0) == (scale > 0) == upper) {
 712     max_idx_expr = new (C, 3) SubINode(limit, stride);
 713     register_new_node(max_idx_expr, ctrl);
 714     if (TraceLoopPredicate) predString->print("(limit - stride) ");
 715   } else {
 716     if (TraceLoopPredicate) predString->print("init ");
 717   }
 718 
 719   if (scale != 1) {
 720     ConNode* con_scale = _igvn.intcon(scale);
 721     max_idx_expr = new (C, 3) MulINode(max_idx_expr, con_scale);
 722     register_new_node(max_idx_expr, ctrl);
 723     if (TraceLoopPredicate) predString->print("* %d ", scale);
 724   }
 725 
 726   if (offset && (!offset->is_Con() || offset->get_int() != 0)){
 727     max_idx_expr = new (C, 3) AddINode(max_idx_expr, offset);
 728     register_new_node(max_idx_expr, ctrl);
 729     if (TraceLoopPredicate)
 730       if (offset->is_Con()) predString->print("+ %d ", offset->get_int());
 731       else predString->print("+ offset ");
 732   }
 733 
 734   CmpUNode* cmp = new (C, 3) CmpUNode(max_idx_expr, range);
 735   register_new_node(cmp, ctrl);
 736   BoolNode* bol = new (C, 2) BoolNode(cmp, BoolTest::lt);
 737   register_new_node(bol, ctrl);
 738 
 739   if (TraceLoopPredicate) {
 740     predString->print_cr("<u range");
 741     tty->print(predString->as_string());
 742   }
 743   return bol;
 744 }
 745 
 746 //------------------------------ loop_predication_impl--------------------------
 747 // Insert loop predicates for null checks and range checks
 748 bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree *loop) {
 749   if (!UseLoopPredicate) return false;
 750 
 751   if (!loop->_head->is_Loop()) {
 752     // Could be a simple region when irreducible loops are present.
 753     return false;
 754   }
 755 
 756   if (loop->_head->unique_ctrl_out()->Opcode() == Op_NeverBranch) {
 757     // do nothing for infinite loops
 758     return false;
 759   }
 760 
 761   CountedLoopNode *cl = NULL;
 762   if (loop->_head->is_CountedLoop()) {


src/share/vm/opto/loopPredicate.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File