diff -r a4cdca87152b -r 77148b8bb7a1 src/hotspot/share/opto/loopopts.cpp --- a/src/hotspot/share/opto/loopopts.cpp Mon Oct 28 11:27:27 2019 +0100 +++ b/src/hotspot/share/opto/loopopts.cpp Wed Oct 23 12:51:53 2019 +0200 @@ -3159,7 +3159,8 @@ Node_List worklist(area); Node_List sink_list(area); - if (!may_require_nodes(loop->est_loop_clone_sz(2))) { + uint estimate = loop->est_loop_clone_sz(1); + if (exceeding_node_budget(estimate)) { return false; } @@ -3184,8 +3185,7 @@ // Set of non-cfg nodes to peel are those that are control // dependent on the cfg nodes. - uint i; - for(i = 0; i < loop->_body.size(); i++ ) { + for (uint i = 0; i < loop->_body.size(); i++) { Node *n = loop->_body.at(i); Node *n_c = has_ctrl(n) ? get_ctrl(n) : n; if (peel.test(n_c->_idx)) { @@ -3200,7 +3200,7 @@ // Get a post order schedule of nodes in the peel region // Result in right-most operand. - scheduled_nodelist(loop, peel, peel_list ); + scheduled_nodelist(loop, peel, peel_list); assert(is_valid_loop_partition(loop, peel, peel_list, not_peel), "bad partition"); @@ -3220,25 +3220,21 @@ // Evacuate nodes in peel region into the not_peeled region if possible uint new_phi_cnt = 0; uint cloned_for_outside_use = 0; - for (i = 0; i < peel_list.size();) { + for (uint i = 0; i < peel_list.size();) { Node* n = peel_list.at(i); #ifndef PRODUCT if (TracePartialPeeling) n->dump(); #endif bool incr = true; - if ( !n->is_CFG() ) { - - if ( has_use_in_set(n, not_peel) ) { - + if (!n->is_CFG()) { + if (has_use_in_set(n, not_peel)) { // If not used internal to the peeled region, // move "n" from peeled to not_peeled region. - - if ( !has_use_internal_to_set(n, peel, loop) ) { - + if (!has_use_internal_to_set(n, peel, loop)) { // if not pinned and not a load (which maybe anti-dependent on a store) // and not a CMove (Matcher expects only bool->cmove). if (n->in(0) == NULL && !n->is_Load() && !n->is_CMove()) { - cloned_for_outside_use += clone_for_use_outside_loop( loop, n, worklist ); + cloned_for_outside_use += clone_for_use_outside_loop(loop, n, worklist); sink_list.push(n); peel >>= n->_idx; // delete n from peel set. not_peel <<= n->_idx; // add n to not_peel set. @@ -3254,7 +3250,7 @@ } else { // Otherwise check for special def-use cases that span // the peel/not_peel boundary such as bool->if - clone_for_special_use_inside_loop( loop, n, not_peel, sink_list, worklist ); + clone_for_special_use_inside_loop(loop, n, not_peel, sink_list, worklist); new_phi_cnt++; } } @@ -3262,7 +3258,11 @@ if (incr) i++; } - if (new_phi_cnt > old_phi_cnt + PartialPeelNewPhiDelta) { + estimate += cloned_for_outside_use + new_phi_cnt; + bool exceed_node_budget = !may_require_nodes(estimate); + bool exceed_phi_limit = new_phi_cnt > old_phi_cnt + PartialPeelNewPhiDelta; + + if (exceed_node_budget || exceed_phi_limit) { #ifndef PRODUCT if (TracePartialPeeling) { tty->print_cr("\nToo many new phis: %d old %d new cmpi: %c", @@ -3310,7 +3310,7 @@ const uint clone_exit_idx = 1; const uint orig_exit_idx = 2; - assert(is_valid_clone_loop_form( loop, peel_list, orig_exit_idx, clone_exit_idx ), "bad clone loop"); + assert(is_valid_clone_loop_form(loop, peel_list, orig_exit_idx, clone_exit_idx), "bad clone loop"); Node* head_clone = old_new[head->_idx]; LoopNode* new_head_clone = old_new[new_head->_idx]->as_Loop(); @@ -3318,7 +3318,7 @@ // Add phi if "def" node is in peel set and "use" is not - for(i = 0; i < peel_list.size(); i++ ) { + for (uint i = 0; i < peel_list.size(); i++) { Node *def = peel_list.at(i); if (!def->is_CFG()) { for (DUIterator_Fast jmax, j = def->fast_outs(jmax); j < jmax; j++) { @@ -3374,7 +3374,7 @@ // cloned-not_peeled in(0) in(0) // orig-peeled - for(i = 0; i < loop->_body.size(); i++ ) { + for (uint i = 0; i < loop->_body.size(); i++) { Node *n = loop->_body.at(i); if (!n->is_CFG() && n->in(0) != NULL && not_peel.test(n->_idx) && peel.test(n->in(0)->_idx)) {