1 /*
  2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "memory/allocation.inline.hpp"
 27 #include "opto/callnode.hpp"
 28 #include "opto/inlinetypenode.hpp"
 29 #include "opto/loopnode.hpp"
 30 #include "opto/movenode.hpp"
 31 
 32 
 33 //------------------------------split_thru_region------------------------------
 34 // Split Node 'n' through merge point.
 35 RegionNode* PhaseIdealLoop::split_thru_region(Node* n, RegionNode* region) {
 36   assert(n->is_CFG(), "");
 37   RegionNode* r = new RegionNode(region->req());
 38   IdealLoopTree* loop = get_loop(n);
 39   for (uint i = 1; i < region->req(); i++) {
 40     Node* x = n->clone();
 41     Node* in0 = n->in(0);
 42     if (in0->in(0) == region) x->set_req(0, in0->in(i));
 43     for (uint j = 1; j < n->req(); j++) {
 44       Node* in = n->in(j);
 45       if (get_ctrl(in) == region) {
 46         x->set_req(j, in->in(i));
 47       }
 48     }
 49     _igvn.register_new_node_with_optimizer(x);
 50     set_loop(x, loop);
 51     set_idom(x, x->in(0), dom_depth(x->in(0))+1);
 52     r->init_req(i, x);
 53   }
 54 
 55   // Record region
 56   r->set_req(0,region);         // Not a TRUE RegionNode
 57   _igvn.register_new_node_with_optimizer(r);
 58   set_loop(r, loop);
 59   if (!loop->_child) {
 60     loop->_body.push(r);
 61   }
 62   return r;
 63 }
 64 
 65 //------------------------------split_up---------------------------------------
 66 // Split block-local op up through the phis to empty the current block
 67 bool PhaseIdealLoop::split_up( Node *n, Node *blk1, Node *blk2 ) {
 68   if( n->is_CFG() ) {
 69     assert( n->in(0) != blk1, "Lousy candidate for split-if" );
 70     return false;
 71   }
 72   if( get_ctrl(n) != blk1 && get_ctrl(n) != blk2 )
 73     return false;               // Not block local
 74   if( n->is_Phi() ) return false; // Local PHIs are expected
 75 
 76   // Recursively split-up inputs
 77   for (uint i = 1; i < n->req(); i++) {
 78     if( split_up( n->in(i), blk1, blk2 ) ) {
 79       // Got split recursively and self went dead?
 80       if (n->outcnt() == 0)
 81         _igvn.remove_dead_node(n);
 82       return true;
 83     }
 84   }
 85 
 86   // Check for needing to clone-up a compare.  Can't do that, it forces
 87   // another (nested) split-if transform.  Instead, clone it "down".
 88   if( n->is_Cmp() ) {
 89     assert(get_ctrl(n) == blk2 || get_ctrl(n) == blk1, "must be in block with IF");
 90     // Check for simple Cmp/Bool/CMove which we can clone-up.  Cmp/Bool/CMove
 91     // sequence can have no other users and it must all reside in the split-if
 92     // block.  Non-simple Cmp/Bool/CMove sequences are 'cloned-down' below -
 93     // private, per-use versions of the Cmp and Bool are made.  These sink to
 94     // the CMove block.  If the CMove is in the split-if block, then in the
 95     // next iteration this will become a simple Cmp/Bool/CMove set to clone-up.
 96     Node *bol, *cmov;
 97     if( !(n->outcnt() == 1 && n->unique_out()->is_Bool() &&
 98           (bol = n->unique_out()->as_Bool()) &&
 99           (get_ctrl(bol) == blk1 ||
100            get_ctrl(bol) == blk2) &&
101           bol->outcnt() == 1 &&
102           bol->unique_out()->is_CMove() &&
103           (cmov = bol->unique_out()->as_CMove()) &&
104           (get_ctrl(cmov) == blk1 ||
105            get_ctrl(cmov) == blk2) ) ) {
106 
107       // Must clone down
108 #ifndef PRODUCT
109       if( PrintOpto && VerifyLoopOptimizations ) {
110         tty->print("Cloning down: ");
111         n->dump();
112       }
113 #endif
114       if (!n->is_FastLock()) {
115         // Clone down any block-local BoolNode uses of this CmpNode
116         for (DUIterator i = n->outs(); n->has_out(i); i++) {
117           Node* bol = n->out(i);
118           assert( bol->is_Bool(), "" );
119           if (bol->outcnt() == 1) {
120             Node* use = bol->unique_out();
121             if (use->Opcode() == Op_Opaque4) {
122               if (use->outcnt() == 1) {
123                 Node* iff = use->unique_out();
124                 assert(iff->is_If(), "unexpected node type");
125                 Node *use_c = iff->in(0);
126                 if (use_c == blk1 || use_c == blk2) {
127                   continue;
128                 }
129               }
130             } else {
131               // We might see an Opaque1 from a loop limit check here
132               assert(use->is_If() || use->is_CMove() || use->Opcode() == Op_Opaque1 || use->is_AllocateArray(), "unexpected node type");
133               Node *use_c = (use->is_If() || use->is_AllocateArray()) ? use->in(0) : get_ctrl(use);
134               if (use_c == blk1 || use_c == blk2) {
135                 assert(use->is_CMove(), "unexpected node type");
136                 continue;
137               }
138             }
139           }
140           if (get_ctrl(bol) == blk1 || get_ctrl(bol) == blk2) {
141             // Recursively sink any BoolNode
142 #ifndef PRODUCT
143             if( PrintOpto && VerifyLoopOptimizations ) {
144               tty->print("Cloning down: ");
145               bol->dump();
146             }
147 #endif
148             for (DUIterator j = bol->outs(); bol->has_out(j); j++) {
149               Node* u = bol->out(j);
150               // Uses are either IfNodes, CMoves or Opaque4
151               if (u->Opcode() == Op_Opaque4) {
152                 assert(u->in(1) == bol, "bad input");
153                 for (DUIterator_Last kmin, k = u->last_outs(kmin); k >= kmin; --k) {
154                   Node* iff = u->last_out(k);
155                   assert(iff->is_If() || iff->is_CMove(), "unexpected node type");
156                   assert( iff->in(1) == u, "" );
157                   // Get control block of either the CMove or the If input
158                   Node *iff_ctrl = iff->is_If() ? iff->in(0) : get_ctrl(iff);
159                   Node *x1 = bol->clone();
160                   Node *x2 = u->clone();
161                   register_new_node(x1, iff_ctrl);
162                   register_new_node(x2, iff_ctrl);
163                   _igvn.replace_input_of(x2, 1, x1);
164                   _igvn.replace_input_of(iff, 1, x2);
165                 }
166                 _igvn.remove_dead_node(u);
167                 --j;
168               } else {
169                 // We might see an Opaque1 from a loop limit check here
170                 assert(u->is_If() || u->is_CMove() || u->Opcode() == Op_Opaque1 || u->is_AllocateArray(), "unexpected node type");
171                 assert(u->is_AllocateArray() || u->in(1) == bol, "");
172                 assert(!u->is_AllocateArray() || u->in(AllocateNode::ValidLengthTest) == bol, "wrong input to AllocateArray");
173                 // Get control block of either the CMove or the If input
174                 Node *u_ctrl = (u->is_If() || u->is_AllocateArray()) ? u->in(0) : get_ctrl(u);
175                 assert((u_ctrl != blk1 && u_ctrl != blk2) || u->is_CMove(), "won't converge");
176                 Node *x = bol->clone();
177                 register_new_node(x, u_ctrl);
178                 _igvn.replace_input_of(u, u->is_AllocateArray() ? AllocateNode::ValidLengthTest : 1, x);
179                 --j;
180               }
181             }
182             _igvn.remove_dead_node(bol);
183             --i;
184           }
185         }
186       }
187       // Clone down this CmpNode
188       for (DUIterator_Last jmin, j = n->last_outs(jmin); j >= jmin; --j) {
189         Node* use = n->last_out(j);
190         uint pos = 1;
191         if (n->is_FastLock()) {
192           pos = TypeFunc::Parms + 2;
193           assert(use->is_Lock(), "FastLock only used by LockNode");
194         }
195         assert(use->in(pos) == n, "" );
196         Node *x = n->clone();
197         register_new_node(x, ctrl_or_self(use));
198         _igvn.replace_input_of(use, pos, x);
199       }
200       _igvn.remove_dead_node( n );
201 
202       return true;
203     }
204   }
205   if (n->Opcode() == Op_OpaqueLoopStride || n->Opcode() == Op_OpaqueLoopInit) {
206     Unique_Node_List wq;
207     wq.push(n);
208     for (uint i = 0; i < wq.size(); i++) {
209       Node* m = wq.at(i);
210       if (m->is_If()) {
211         assert(skeleton_predicate_has_opaque(m->as_If()), "opaque node not reachable from if?");
212         Node* bol = clone_skeleton_predicate_bool(m, NULL, NULL, m->in(0));
213         _igvn.replace_input_of(m, 1, bol);
214       } else {
215         assert(!m->is_CFG(), "not CFG expected");
216         for (DUIterator_Fast jmax, j = m->fast_outs(jmax); j < jmax; j++) {
217           Node* u = m->fast_out(j);
218           wq.push(u);
219         }
220       }
221     }
222   }
223 
224   // See if splitting-up a Store.  Any anti-dep loads must go up as
225   // well.  An anti-dep load might be in the wrong block, because in
226   // this particular layout/schedule we ignored anti-deps and allow
227   // memory to be alive twice.  This only works if we do the same
228   // operations on anti-dep loads as we do their killing stores.
229   if( n->is_Store() && n->in(MemNode::Memory)->in(0) == n->in(0) ) {
230     // Get store's memory slice
231     int alias_idx = C->get_alias_index(_igvn.type(n->in(MemNode::Address))->is_ptr());
232 
233     // Get memory-phi anti-dep loads will be using
234     Node *memphi = n->in(MemNode::Memory);
235     assert( memphi->is_Phi(), "" );
236     // Hoist any anti-dep load to the splitting block;
237     // it will then "split-up".
238     for (DUIterator_Fast imax,i = memphi->fast_outs(imax); i < imax; i++) {
239       Node *load = memphi->fast_out(i);
240       if( load->is_Load() && alias_idx == C->get_alias_index(_igvn.type(load->in(MemNode::Address))->is_ptr()) )
241         set_ctrl(load,blk1);
242     }
243   }
244 
245   // Found some other Node; must clone it up
246 #ifndef PRODUCT
247   if( PrintOpto && VerifyLoopOptimizations ) {
248     tty->print("Cloning up: ");
249     n->dump();
250   }
251 #endif
252 
253   // ConvI2L may have type information on it which becomes invalid if
254   // it moves up in the graph so change any clones so widen the type
255   // to TypeLong::INT when pushing it up.
256   const Type* rtype = NULL;
257   if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::INT) {
258     rtype = TypeLong::INT;
259   }
260 
261   // Now actually split-up this guy.  One copy per control path merging.
262   Node *phi = PhiNode::make_blank(blk1, n);
263   for( uint j = 1; j < blk1->req(); j++ ) {
264     Node *x = n->clone();
265     // Widen the type of the ConvI2L when pushing up.
266     if (rtype != NULL) x->as_Type()->set_type(rtype);
267     if( n->in(0) && n->in(0) == blk1 )
268       x->set_req( 0, blk1->in(j) );
269     for( uint i = 1; i < n->req(); i++ ) {
270       Node *m = n->in(i);
271       if( get_ctrl(m) == blk1 ) {
272         assert( m->in(0) == blk1, "" );
273         x->set_req( i, m->in(j) );
274       }
275     }
276     register_new_node( x, blk1->in(j) );
277     phi->init_req( j, x );
278   }
279   // Announce phi to optimizer
280   register_new_node(phi, blk1);
281 
282   // Remove cloned-up value from optimizer; use phi instead
283   _igvn.replace_node( n, phi );
284 
285   // (There used to be a self-recursive call to split_up() here,
286   // but it is not needed.  All necessary forward walking is done
287   // by do_split_if() below.)
288 
289   return true;
290 }
291 
292 //------------------------------register_new_node------------------------------
293 void PhaseIdealLoop::register_new_node( Node *n, Node *blk ) {
294   assert(!n->is_CFG(), "must be data node");
295   _igvn.register_new_node_with_optimizer(n);
296   set_ctrl(n, blk);
297   IdealLoopTree *loop = get_loop(blk);
298   if( !loop->_child )
299     loop->_body.push(n);
300 }
301 
302 //------------------------------small_cache------------------------------------
303 struct small_cache : public Dict {
304 
305   small_cache() : Dict( cmpkey, hashptr ) {}
306   Node *probe( Node *use_blk ) { return (Node*)((*this)[use_blk]); }
307   void lru_insert( Node *use_blk, Node *new_def ) { Insert(use_blk,new_def); }
308 };
309 
310 //------------------------------spinup-----------------------------------------
311 // "Spin up" the dominator tree, starting at the use site and stopping when we
312 // find the post-dominating point.
313 
314 // We must be at the merge point which post-dominates 'new_false' and
315 // 'new_true'.  Figure out which edges into the RegionNode eventually lead up
316 // to false and which to true.  Put in a PhiNode to merge values; plug in
317 // the appropriate false-arm or true-arm values.  If some path leads to the
318 // original IF, then insert a Phi recursively.
319 Node *PhaseIdealLoop::spinup( Node *iff_dom, Node *new_false, Node *new_true, Node *use_blk, Node *def, small_cache *cache ) {
320   if (use_blk->is_top())        // Handle dead uses
321     return use_blk;
322   Node *prior_n = (Node*)((intptr_t)0xdeadbeef);
323   Node *n = use_blk;            // Get path input
324   assert( use_blk != iff_dom, "" );
325   // Here's the "spinup" the dominator tree loop.  Do a cache-check
326   // along the way, in case we've come this way before.
327   while( n != iff_dom ) {       // Found post-dominating point?
328     prior_n = n;
329     n = idom(n);                // Search higher
330     Node *s = cache->probe( prior_n ); // Check cache
331     if( s ) return s;           // Cache hit!
332   }
333 
334   Node *phi_post;
335   if( prior_n == new_false || prior_n == new_true ) {
336     phi_post = def->clone();
337     phi_post->set_req(0, prior_n );
338     register_new_node(phi_post, prior_n);
339   } else {
340     // This method handles both control uses (looking for Regions) or data
341     // uses (looking for Phis).  If looking for a control use, then we need
342     // to insert a Region instead of a Phi; however Regions always exist
343     // previously (the hash_find_insert below would always hit) so we can
344     // return the existing Region.
345     if( def->is_CFG() ) {
346       phi_post = prior_n;       // If looking for CFG, return prior
347     } else {
348       assert( def->is_Phi(), "" );
349       assert( prior_n->is_Region(), "must be a post-dominating merge point" );
350 
351       // Need a Phi here
352       phi_post = PhiNode::make_blank(prior_n, def);
353       // Search for both true and false on all paths till find one.
354       for( uint i = 1; i < phi_post->req(); i++ ) // For all paths
355         phi_post->init_req( i, spinup( iff_dom, new_false, new_true, prior_n->in(i), def, cache ) );
356       Node *t = _igvn.hash_find_insert(phi_post);
357       if( t ) {                 // See if we already have this one
358         // phi_post will not be used, so kill it
359         _igvn.remove_dead_node(phi_post);
360         phi_post->destruct(&_igvn);
361         phi_post = t;
362       } else {
363         register_new_node( phi_post, prior_n );
364       }
365     }
366   }
367 
368   // Update cache everywhere
369   prior_n = (Node*)((intptr_t)0xdeadbeef);  // Reset IDOM walk
370   n = use_blk;                  // Get path input
371   // Spin-up the idom tree again, basically doing path-compression.
372   // Insert cache entries along the way, so that if we ever hit this
373   // point in the IDOM tree again we'll stop immediately on a cache hit.
374   while( n != iff_dom ) {       // Found post-dominating point?
375     prior_n = n;
376     n = idom(n);                // Search higher
377     cache->lru_insert( prior_n, phi_post ); // Fill cache
378   } // End of while not gone high enough
379 
380   return phi_post;
381 }
382 
383 //------------------------------find_use_block---------------------------------
384 // Find the block a USE is in.  Normally USE's are in the same block as the
385 // using instruction.  For Phi-USE's, the USE is in the predecessor block
386 // along the corresponding path.
387 Node *PhaseIdealLoop::find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true ) {
388   // CFG uses are their own block
389   if( use->is_CFG() )
390     return use;
391 
392   if( use->is_Phi() ) {         // Phi uses in prior block
393     // Grab the first Phi use; there may be many.
394     // Each will be handled as a separate iteration of
395     // the "while( phi->outcnt() )" loop.
396     uint j;
397     for( j = 1; j < use->req(); j++ )
398       if( use->in(j) == def )
399         break;
400     assert( j < use->req(), "def should be among use's inputs" );
401     return use->in(0)->in(j);
402   }
403   // Normal (non-phi) use
404   Node *use_blk = get_ctrl(use);
405   // Some uses are directly attached to the old (and going away)
406   // false and true branches.
407   if( use_blk == old_false ) {
408     use_blk = new_false;
409     set_ctrl(use, new_false);
410   }
411   if( use_blk == old_true ) {
412     use_blk = new_true;
413     set_ctrl(use, new_true);
414   }
415 
416   if (use_blk == NULL) {        // He's dead, Jim
417     _igvn.replace_node(use, C->top());
418   }
419 
420   return use_blk;
421 }
422 
423 //------------------------------handle_use-------------------------------------
424 // Handle uses of the merge point.  Basically, split-if makes the merge point
425 // go away so all uses of the merge point must go away as well.  Most block
426 // local uses have already been split-up, through the merge point.  Uses from
427 // far below the merge point can't always be split up (e.g., phi-uses are
428 // pinned) and it makes too much stuff live.  Instead we use a path-based
429 // solution to move uses down.
430 //
431 // If the use is along the pre-split-CFG true branch, then the new use will
432 // be from the post-split-CFG true merge point.  Vice-versa for the false
433 // path.  Some uses will be along both paths; then we sink the use to the
434 // post-dominating location; we may need to insert a Phi there.
435 void PhaseIdealLoop::handle_use( Node *use, Node *def, small_cache *cache, Node *region_dom, Node *new_false, Node *new_true, Node *old_false, Node *old_true ) {
436 
437   Node *use_blk = find_use_block(use,def,old_false,new_false,old_true,new_true);
438   if( !use_blk ) return;        // He's dead, Jim
439 
440   // Walk up the dominator tree until I hit either the old IfFalse, the old
441   // IfTrue or the old If.  Insert Phis where needed.
442   Node *new_def = spinup( region_dom, new_false, new_true, use_blk, def, cache );
443 
444   // Found where this USE goes.  Re-point him.
445   uint i;
446   for( i = 0; i < use->req(); i++ )
447     if( use->in(i) == def )
448       break;
449   assert( i < use->req(), "def should be among use's inputs" );
450   _igvn.replace_input_of(use, i, new_def);
451 }
452 
453 //------------------------------do_split_if------------------------------------
454 // Found an If getting its condition-code input from a Phi in the same block.
455 // Split thru the Region.
456 void PhaseIdealLoop::do_split_if(Node* iff, RegionNode** new_false_region, RegionNode** new_true_region) {
457   if (PrintOpto && VerifyLoopOptimizations) {
458     tty->print_cr("Split-if");
459   }
460   if (TraceLoopOpts) {
461     tty->print_cr("SplitIf");
462   }
463 
464   C->set_major_progress();
465   RegionNode *region = iff->in(0)->as_Region();
466   Node *region_dom = idom(region);
467 
468   // We are going to clone this test (and the control flow with it) up through
469   // the incoming merge point.  We need to empty the current basic block.
470   // Clone any instructions which must be in this block up through the merge
471   // point.
472   DUIterator i, j;
473   bool progress = true;
474   while (progress) {
475     progress = false;
476     for (i = region->outs(); region->has_out(i); i++) {
477       Node* n = region->out(i);
478       if( n == region ) continue;
479       // The IF to be split is OK.
480       if( n == iff ) continue;
481       if( !n->is_Phi() ) {      // Found pinned memory op or such
482         if (split_up(n, region, iff)) {
483           i = region->refresh_out_pos(i);
484           progress = true;
485         }
486         continue;
487       }
488       assert( n->in(0) == region, "" );
489 
490       // Recursively split up all users of a Phi
491       for (j = n->outs(); n->has_out(j); j++) {
492         Node* m = n->out(j);
493         // If m is dead, throw it away, and declare progress
494         if (_nodes[m->_idx] == NULL) {
495           _igvn.remove_dead_node(m);
496           // fall through
497         } else if (m != iff && split_up(m, region, iff)) {
498           // fall through
499         } else {
500           continue;
501         }
502         // Something unpredictable changed.
503         // Tell the iterators to refresh themselves, and rerun the loop.
504         i = region->refresh_out_pos(i);
505         j = region->refresh_out_pos(j);
506         progress = true;
507       }
508     }
509   }
510 
511   // Now we have no instructions in the block containing the IF.
512   // Split the IF.
513   RegionNode *new_iff = split_thru_region(iff, region);
514 
515   // Replace both uses of 'new_iff' with Regions merging True/False
516   // paths.  This makes 'new_iff' go dead.
517   Node *old_false = NULL, *old_true = NULL;
518   RegionNode* new_false = NULL;
519   RegionNode* new_true = NULL;
520   for (DUIterator_Last j2min, j2 = iff->last_outs(j2min); j2 >= j2min; --j2) {
521     Node *ifp = iff->last_out(j2);
522     assert( ifp->Opcode() == Op_IfFalse || ifp->Opcode() == Op_IfTrue, "" );
523     ifp->set_req(0, new_iff);
524     RegionNode* ifpx = split_thru_region(ifp, region);
525 
526     // Replace 'If' projection of a Region with a Region of
527     // 'If' projections.
528     ifpx->set_req(0, ifpx);       // A TRUE RegionNode
529 
530     // Setup dominator info
531     set_idom(ifpx, region_dom, dom_depth(region_dom) + 1);
532 
533     // Check for splitting loop tails
534     if( get_loop(iff)->tail() == ifp )
535       get_loop(iff)->_tail = ifpx;
536 
537     // Replace in the graph with lazy-update mechanism
538     new_iff->set_req(0, new_iff); // hook self so it does not go dead
539     lazy_replace(ifp, ifpx);
540     new_iff->set_req(0, region);
541 
542     // Record bits for later xforms
543     if( ifp->Opcode() == Op_IfFalse ) {
544       old_false = ifp;
545       new_false = ifpx;
546     } else {
547       old_true = ifp;
548       new_true = ifpx;
549     }
550   }
551   _igvn.remove_dead_node(new_iff);
552   // Lazy replace IDOM info with the region's dominator
553   lazy_replace(iff, region_dom);
554   lazy_update(region, region_dom); // idom must be update before handle_uses
555   region->set_req(0, NULL);        // Break the self-cycle. Required for lazy_update to work on region
556 
557   // Now make the original merge point go dead, by handling all its uses.
558   small_cache region_cache;
559   // Preload some control flow in region-cache
560   region_cache.lru_insert( new_false, new_false );
561   region_cache.lru_insert( new_true , new_true  );
562   // Now handle all uses of the splitting block
563   for (DUIterator k = region->outs(); region->has_out(k); k++) {
564     Node* phi = region->out(k);
565     if (!phi->in(0)) {         // Dead phi?  Remove it
566       _igvn.remove_dead_node(phi);
567     } else if (phi == region) { // Found the self-reference
568       continue;                 // No roll-back of DUIterator
569     } else if (phi->is_Phi()) { // Expected common case: Phi hanging off of Region
570       assert(phi->in(0) == region, "Inconsistent graph");
571       // Need a per-def cache.  Phi represents a def, so make a cache
572       small_cache phi_cache;
573 
574       // Inspect all Phi uses to make the Phi go dead
575       for (DUIterator_Last lmin, l = phi->last_outs(lmin); l >= lmin; --l) {
576         Node* use = phi->last_out(l);
577         // Compute the new DEF for this USE.  New DEF depends on the path
578         // taken from the original DEF to the USE.  The new DEF may be some
579         // collection of PHI's merging values from different paths.  The Phis
580         // inserted depend only on the location of the USE.  We use a
581         // 2-element cache to handle multiple uses from the same block.
582         handle_use(use, phi, &phi_cache, region_dom, new_false, new_true, old_false, old_true);
583       } // End of while phi has uses
584       // Remove the dead Phi
585       _igvn.remove_dead_node( phi );
586     } else {
587       assert(phi->in(0) == region, "Inconsistent graph");
588       // Random memory op guarded by Region.  Compute new DEF for USE.
589       handle_use(phi, region, &region_cache, region_dom, new_false, new_true, old_false, old_true);
590     }
591     // Every path above deletes a use of the region, except for the region
592     // self-cycle (which is needed by handle_use calling find_use_block
593     // calling get_ctrl calling get_ctrl_no_update looking for dead
594     // regions).  So roll back the DUIterator innards.
595     --k;
596   } // End of while merge point has phis
597 
598   _igvn.remove_dead_node(region);
599 
600   if (new_false_region != NULL) {
601     *new_false_region = new_false;
602   }
603   if (new_true_region != NULL) {
604     *new_true_region = new_true;
605   }
606 
607 #ifndef PRODUCT
608   if( VerifyLoopOptimizations ) verify();
609 #endif
610 }