@@ -3701,29 +3701,21 @@ bool IdealLoopTree::do_remove_empty_loop(PhaseIdealLoop *phase) {
37013701 }
37023702
37033703 // Replace the phi at loop head with the final value of the last
3704- // iteration. Then the CountedLoopEnd will collapse (backedge never
3705- // taken) and all loop-invariant uses of the exit values will be correct.
3706- Node *phi = cl->phi ();
3707- Node *exact_limit = phase->exact_limit (this );
3708- if (exact_limit != cl->limit ()) {
3709- // We also need to replace the original limit to collapse loop exit.
3710- Node* cmp = cl->loopexit ()->cmp_node ();
3711- assert (cl->limit () == cmp->in (2 ), " sanity" );
3712- // Duplicate cmp node if it has other users
3713- if (cmp->outcnt () > 1 ) {
3714- cmp = cmp->clone ();
3715- cmp = phase->_igvn .register_new_node_with_optimizer (cmp);
3716- BoolNode *bol = cl->loopexit ()->in (CountedLoopEndNode::TestValue)->as_Bool ();
3717- phase->_igvn .replace_input_of (bol, 1 , cmp); // put bol on worklist
3718- }
3719- phase->_igvn ._worklist .push (cmp->in (2 )); // put limit on worklist
3720- phase->_igvn .replace_input_of (cmp, 2 , exact_limit); // put cmp on worklist
3721- }
3704+ // iteration (exact_limit - stride), to make sure the loop exit value
3705+ // is correct, for any users after the loop.
37223706 // Note: the final value after increment should not overflow since
37233707 // counted loop has limit check predicate.
3724- Node *final = new SubINode (exact_limit, cl->stride ());
3725- phase->register_new_node (final ,cl->in (LoopNode::EntryControl));
3726- phase->_igvn .replace_node (phi,final );
3708+ Node* phi = cl->phi ();
3709+ Node* exact_limit = phase->exact_limit (this );
3710+ Node* final_iv = new SubINode (exact_limit, cl->stride ());
3711+ phase->register_new_node (final_iv, cl->in (LoopNode::EntryControl));
3712+ phase->_igvn .replace_node (phi, final_iv);
3713+
3714+ // Set loop-exit condition to false. Then the CountedLoopEnd will collapse,
3715+ // because the back edge is never taken.
3716+ Node* zero = phase->_igvn .intcon (0 );
3717+ phase->_igvn .replace_input_of (cl->loopexit (), CountedLoopEndNode::TestValue, zero);
3718+
37273719 phase->C ->set_major_progress ();
37283720 return true ;
37293721}
0 commit comments