@@ -3396,29 +3396,21 @@ bool IdealLoopTree::do_remove_empty_loop(PhaseIdealLoop *phase) {
33963396 }
33973397
33983398 // Replace the phi at loop head with the final value of the last
3399- // iteration. Then the CountedLoopEnd will collapse (backedge never
3400- // taken) and all loop-invariant uses of the exit values will be correct.
3401- Node *phi = cl->phi ();
3402- Node *exact_limit = phase->exact_limit (this );
3403- if (exact_limit != cl->limit ()) {
3404- // We also need to replace the original limit to collapse loop exit.
3405- Node* cmp = cl->loopexit ()->cmp_node ();
3406- assert (cl->limit () == cmp->in (2 ), " sanity" );
3407- // Duplicate cmp node if it has other users
3408- if (cmp->outcnt () > 1 ) {
3409- cmp = cmp->clone ();
3410- cmp = phase->_igvn .register_new_node_with_optimizer (cmp);
3411- BoolNode *bol = cl->loopexit ()->in (CountedLoopEndNode::TestValue)->as_Bool ();
3412- phase->_igvn .replace_input_of (bol, 1 , cmp); // put bol on worklist
3413- }
3414- phase->_igvn ._worklist .push (cmp->in (2 )); // put limit on worklist
3415- phase->_igvn .replace_input_of (cmp, 2 , exact_limit); // put cmp on worklist
3416- }
3399+ // iteration (exact_limit - stride), to make sure the loop exit value
3400+ // is correct, for any users after the loop.
34173401 // Note: the final value after increment should not overflow since
34183402 // counted loop has limit check predicate.
3419- Node *final = new SubINode (exact_limit, cl->stride ());
3420- phase->register_new_node (final ,cl->in (LoopNode::EntryControl));
3421- phase->_igvn .replace_node (phi,final );
3403+ Node* phi = cl->phi ();
3404+ Node* exact_limit = phase->exact_limit (this );
3405+ Node* final_iv = new SubINode (exact_limit, cl->stride ());
3406+ phase->register_new_node (final_iv, cl->in (LoopNode::EntryControl));
3407+ phase->_igvn .replace_node (phi, final_iv);
3408+
3409+ // Set loop-exit condition to false. Then the CountedLoopEnd will collapse,
3410+ // because the back edge is never taken.
3411+ Node* zero = phase->_igvn .intcon (0 );
3412+ phase->_igvn .replace_input_of (cl->loopexit (), CountedLoopEndNode::TestValue, zero);
3413+
34223414 phase->C ->set_major_progress ();
34233415 return true ;
34243416}
0 commit comments