696
697 // After unroll limit will be adjusted: new_limit = limit-stride.
698 // Bailout if adjustment overflow.
699 const TypeInt* limit_type = phase->_igvn.type(limit_n)->is_int();
700 if (stride_con > 0 && ((limit_type->_hi - stride_con) >= limit_type->_hi) ||
701 stride_con < 0 && ((limit_type->_lo - stride_con) <= limit_type->_lo))
702 return false; // overflow
703
704 // Adjust body_size to determine if we unroll or not
705 uint body_size = _body.size();
706 // Key test to unroll loop in CRC32 java code
707 int xors_in_loop = 0;
708 // Also count ModL, DivL and MulL which expand mightly
709 for (uint k = 0; k < _body.size(); k++) {
710 Node* n = _body.at(k);
711 switch (n->Opcode()) {
712 case Op_XorI: xors_in_loop++; break; // CRC32 java code
713 case Op_ModL: body_size += 30; break;
714 case Op_DivL: body_size += 30; break;
715 case Op_MulL: body_size += 10; break;
716 case Op_FlagsProj:
717 // Can't handle unrolling of loops containing
718 // nodes that generate a FlagsProj at the moment
719 return false;
720 case Op_StrComp:
721 case Op_StrEquals:
722 case Op_StrIndexOf:
723 case Op_EncodeISOArray:
724 case Op_AryEq: {
725 // Do not unroll a loop with String intrinsics code.
726 // String intrinsics are large and have loops.
727 return false;
728 }
729 } // switch
730 }
731
732 // Check for being too big
733 if (body_size > (uint)LoopUnrollLimit) {
734 if (xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true;
735 // Normal case: loop too big
736 return false;
737 }
738
739 // Unroll once! (Each trip will soon do double iterations)
763 if (cl->is_main_no_pre_loop()) return false; // Disallowed for now.
764 Node *trip_counter = cl->phi();
765
766 // Check loop body for tests of trip-counter plus loop-invariant vs
767 // loop-invariant.
768 for (uint i = 0; i < _body.size(); i++) {
769 Node *iff = _body[i];
770 if (iff->Opcode() == Op_If) { // Test?
771
772 // Comparing trip+off vs limit
773 Node *bol = iff->in(1);
774 if (bol->req() != 2) continue; // dead constant test
775 if (!bol->is_Bool()) {
776 assert(UseLoopPredicate && bol->Opcode() == Op_Conv2B, "predicate check only");
777 continue;
778 }
779 if (bol->as_Bool()->_test._test == BoolTest::ne)
780 continue; // not RC
781
782 Node *cmp = bol->in(1);
783 if (cmp->is_FlagsProj()) {
784 continue;
785 }
786
787 Node *rc_exp = cmp->in(1);
788 Node *limit = cmp->in(2);
789
790 Node *limit_c = phase->get_ctrl(limit);
791 if( limit_c == phase->C->top() )
792 return false; // Found dead test on live IF? No RCE!
793 if( is_member(phase->get_loop(limit_c) ) ) {
794 // Compare might have operands swapped; commute them
795 rc_exp = cmp->in(2);
796 limit = cmp->in(1);
797 limit_c = phase->get_ctrl(limit);
798 if( is_member(phase->get_loop(limit_c) ) )
799 continue; // Both inputs are loop varying; cannot RCE
800 }
801
802 if (!phase->is_scaled_iv_plus_offset(rc_exp, trip_counter, NULL, NULL)) {
803 continue;
804 }
805 // Yeah! Found a test like 'trip+off vs limit'
806 // Test is an IfNode, has 2 projections. If BOTH are in the loop
|
696
697 // After unroll limit will be adjusted: new_limit = limit-stride.
698 // Bailout if adjustment overflow.
699 const TypeInt* limit_type = phase->_igvn.type(limit_n)->is_int();
700 if (stride_con > 0 && ((limit_type->_hi - stride_con) >= limit_type->_hi) ||
701 stride_con < 0 && ((limit_type->_lo - stride_con) <= limit_type->_lo))
702 return false; // overflow
703
704 // Adjust body_size to determine if we unroll or not
705 uint body_size = _body.size();
706 // Key test to unroll loop in CRC32 java code
707 int xors_in_loop = 0;
708 // Also count ModL, DivL and MulL which expand mightly
709 for (uint k = 0; k < _body.size(); k++) {
710 Node* n = _body.at(k);
711 switch (n->Opcode()) {
712 case Op_XorI: xors_in_loop++; break; // CRC32 java code
713 case Op_ModL: body_size += 30; break;
714 case Op_DivL: body_size += 30; break;
715 case Op_MulL: body_size += 10; break;
716 case Op_StrComp:
717 case Op_StrEquals:
718 case Op_StrIndexOf:
719 case Op_EncodeISOArray:
720 case Op_AryEq: {
721 // Do not unroll a loop with String intrinsics code.
722 // String intrinsics are large and have loops.
723 return false;
724 }
725 } // switch
726 }
727
728 // Check for being too big
729 if (body_size > (uint)LoopUnrollLimit) {
730 if (xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true;
731 // Normal case: loop too big
732 return false;
733 }
734
735 // Unroll once! (Each trip will soon do double iterations)
759 if (cl->is_main_no_pre_loop()) return false; // Disallowed for now.
760 Node *trip_counter = cl->phi();
761
762 // Check loop body for tests of trip-counter plus loop-invariant vs
763 // loop-invariant.
764 for (uint i = 0; i < _body.size(); i++) {
765 Node *iff = _body[i];
766 if (iff->Opcode() == Op_If) { // Test?
767
768 // Comparing trip+off vs limit
769 Node *bol = iff->in(1);
770 if (bol->req() != 2) continue; // dead constant test
771 if (!bol->is_Bool()) {
772 assert(UseLoopPredicate && bol->Opcode() == Op_Conv2B, "predicate check only");
773 continue;
774 }
775 if (bol->as_Bool()->_test._test == BoolTest::ne)
776 continue; // not RC
777
778 Node *cmp = bol->in(1);
779 Node *rc_exp = cmp->in(1);
780 Node *limit = cmp->in(2);
781
782 Node *limit_c = phase->get_ctrl(limit);
783 if( limit_c == phase->C->top() )
784 return false; // Found dead test on live IF? No RCE!
785 if( is_member(phase->get_loop(limit_c) ) ) {
786 // Compare might have operands swapped; commute them
787 rc_exp = cmp->in(2);
788 limit = cmp->in(1);
789 limit_c = phase->get_ctrl(limit);
790 if( is_member(phase->get_loop(limit_c) ) )
791 continue; // Both inputs are loop varying; cannot RCE
792 }
793
794 if (!phase->is_scaled_iv_plus_offset(rc_exp, trip_counter, NULL, NULL)) {
795 continue;
796 }
797 // Yeah! Found a test like 'trip+off vs limit'
798 // Test is an IfNode, has 2 projections. If BOTH are in the loop
|