src/share/vm/opto/split_if.cpp

changeset 435
a61af66fc99e
child 1040
98cb887364d3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/opto/split_if.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,536 @@
     1.4 +/*
     1.5 + * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_split_if.cpp.incl"
    1.30 +
    1.31 +
    1.32 +//------------------------------split_thru_region------------------------------
    1.33 +// Split Node 'n' through merge point.
    1.34 +Node *PhaseIdealLoop::split_thru_region( Node *n, Node *region ) {
    1.35 +  uint wins = 0;
    1.36 +  assert( n->is_CFG(), "" );
    1.37 +  assert( region->is_Region(), "" );
    1.38 +  Node *r = new (C, region->req()) RegionNode( region->req() );
    1.39 +  IdealLoopTree *loop = get_loop( n );
    1.40 +  for( uint i = 1; i < region->req(); i++ ) {
    1.41 +    Node *x = n->clone();
    1.42 +    Node *in0 = n->in(0);
    1.43 +    if( in0->in(0) == region ) x->set_req( 0, in0->in(i) );
    1.44 +    for( uint j = 1; j < n->req(); j++ ) {
    1.45 +      Node *in = n->in(j);
    1.46 +      if( get_ctrl(in) == region )
    1.47 +        x->set_req( j, in->in(i) );
    1.48 +    }
    1.49 +    _igvn.register_new_node_with_optimizer(x);
    1.50 +    set_loop(x, loop);
    1.51 +    set_idom(x, x->in(0), dom_depth(x->in(0))+1);
    1.52 +    r->init_req(i, x);
    1.53 +  }
    1.54 +
    1.55 +  // Record region
    1.56 +  r->set_req(0,region);         // Not a TRUE RegionNode
    1.57 +  _igvn.register_new_node_with_optimizer(r);
    1.58 +  set_loop(r, loop);
    1.59 +  if( !loop->_child )
    1.60 +    loop->_body.push(r);
    1.61 +  return r;
    1.62 +}
    1.63 +
    1.64 +//------------------------------split_up---------------------------------------
    1.65 +// Split block-local op up through the phis to empty the current block
    1.66 +bool PhaseIdealLoop::split_up( Node *n, Node *blk1, Node *blk2 ) {
    1.67 +  if( n->is_CFG() ) {
    1.68 +    assert( n->in(0) != blk1, "Lousy candidate for split-if" );
    1.69 +    return false;
    1.70 +  }
    1.71 +  if( get_ctrl(n) != blk1 && get_ctrl(n) != blk2 )
    1.72 +    return false;               // Not block local
    1.73 +  if( n->is_Phi() ) return false; // Local PHIs are expected
    1.74 +
    1.75 +  // Recursively split-up inputs
    1.76 +  for (uint i = 1; i < n->req(); i++) {
    1.77 +    if( split_up( n->in(i), blk1, blk2 ) ) {
    1.78 +      // Got split recursively and self went dead?
    1.79 +      if (n->outcnt() == 0)
    1.80 +        _igvn.remove_dead_node(n);
    1.81 +      return true;
    1.82 +    }
    1.83 +  }
    1.84 +
    1.85 +  // Check for needing to clone-up a compare.  Can't do that, it forces
    1.86 +  // another (nested) split-if transform.  Instead, clone it "down".
    1.87 +  if( n->is_Cmp() ) {
    1.88 +    assert(get_ctrl(n) == blk2 || get_ctrl(n) == blk1, "must be in block with IF");
    1.89 +    // Check for simple Cmp/Bool/CMove which we can clone-up.  Cmp/Bool/CMove
    1.90 +    // sequence can have no other users and it must all reside in the split-if
    1.91 +    // block.  Non-simple Cmp/Bool/CMove sequences are 'cloned-down' below -
    1.92 +    // private, per-use versions of the Cmp and Bool are made.  These sink to
    1.93 +    // the CMove block.  If the CMove is in the split-if block, then in the
    1.94 +    // next iteration this will become a simple Cmp/Bool/CMove set to clone-up.
    1.95 +    Node *bol, *cmov;
    1.96 +    if( !(n->outcnt() == 1 && n->unique_out()->is_Bool() &&
    1.97 +          (bol = n->unique_out()->as_Bool()) &&
    1.98 +          (get_ctrl(bol) == blk1 ||
    1.99 +           get_ctrl(bol) == blk2) &&
   1.100 +          bol->outcnt() == 1 &&
   1.101 +          bol->unique_out()->is_CMove() &&
   1.102 +          (cmov = bol->unique_out()->as_CMove()) &&
   1.103 +          (get_ctrl(cmov) == blk1 ||
   1.104 +           get_ctrl(cmov) == blk2) ) ) {
   1.105 +
   1.106 +      // Must clone down
   1.107 +#ifndef PRODUCT
   1.108 +      if( PrintOpto && VerifyLoopOptimizations ) {
   1.109 +        tty->print("Cloning down: ");
   1.110 +        n->dump();
   1.111 +      }
   1.112 +#endif
   1.113 +      // Clone down any block-local BoolNode uses of this CmpNode
   1.114 +      for (DUIterator i = n->outs(); n->has_out(i); i++) {
   1.115 +        Node* bol = n->out(i);
   1.116 +        assert( bol->is_Bool(), "" );
   1.117 +        if (bol->outcnt() == 1) {
   1.118 +          Node* use = bol->unique_out();
   1.119 +          Node *use_c = use->is_If() ? use->in(0) : get_ctrl(use);
   1.120 +          if (use_c == blk1 || use_c == blk2) {
   1.121 +            continue;
   1.122 +          }
   1.123 +        }
   1.124 +        if (get_ctrl(bol) == blk1 || get_ctrl(bol) == blk2) {
   1.125 +          // Recursively sink any BoolNode
   1.126 +#ifndef PRODUCT
   1.127 +          if( PrintOpto && VerifyLoopOptimizations ) {
   1.128 +            tty->print("Cloning down: ");
   1.129 +            bol->dump();
   1.130 +          }
   1.131 +#endif
   1.132 +          for (DUIterator_Last jmin, j = bol->last_outs(jmin); j >= jmin; --j) {
   1.133 +            // Uses are either IfNodes or CMoves
   1.134 +            Node* iff = bol->last_out(j);
   1.135 +            assert( iff->in(1) == bol, "" );
   1.136 +            // Get control block of either the CMove or the If input
   1.137 +            Node *iff_ctrl = iff->is_If() ? iff->in(0) : get_ctrl(iff);
   1.138 +            Node *x = bol->clone();
   1.139 +            register_new_node(x, iff_ctrl);
   1.140 +            _igvn.hash_delete(iff);
   1.141 +            iff->set_req(1, x);
   1.142 +            _igvn._worklist.push(iff);
   1.143 +          }
   1.144 +          _igvn.remove_dead_node( bol );
   1.145 +          --i;
   1.146 +        }
   1.147 +      }
   1.148 +      // Clone down this CmpNode
   1.149 +      for (DUIterator_Last jmin, j = n->last_outs(jmin); j >= jmin; --j) {
   1.150 +        Node* bol = n->last_out(j);
   1.151 +        assert( bol->in(1) == n, "" );
   1.152 +        Node *x = n->clone();
   1.153 +        register_new_node(x, get_ctrl(bol));
   1.154 +        _igvn.hash_delete(bol);
   1.155 +        bol->set_req(1, x);
   1.156 +        _igvn._worklist.push(bol);
   1.157 +      }
   1.158 +      _igvn.remove_dead_node( n );
   1.159 +
   1.160 +      return true;
   1.161 +    }
   1.162 +  }
   1.163 +
   1.164 +  // See if splitting-up a Store.  Any anti-dep loads must go up as
   1.165 +  // well.  An anti-dep load might be in the wrong block, because in
   1.166 +  // this particular layout/schedule we ignored anti-deps and allow
   1.167 +  // memory to be alive twice.  This only works if we do the same
   1.168 +  // operations on anti-dep loads as we do their killing stores.
   1.169 +  if( n->is_Store() && n->in(MemNode::Memory)->in(0) == n->in(0) ) {
   1.170 +    // Get store's memory slice
   1.171 +    int alias_idx = C->get_alias_index(_igvn.type(n->in(MemNode::Address))->is_ptr());
   1.172 +
   1.173 +    // Get memory-phi anti-dep loads will be using
   1.174 +    Node *memphi = n->in(MemNode::Memory);
   1.175 +    assert( memphi->is_Phi(), "" );
   1.176 +    // Hoist any anti-dep load to the splitting block;
   1.177 +    // it will then "split-up".
   1.178 +    for (DUIterator_Fast imax,i = memphi->fast_outs(imax); i < imax; i++) {
   1.179 +      Node *load = memphi->fast_out(i);
   1.180 +      if( load->is_Load() && alias_idx == C->get_alias_index(_igvn.type(load->in(MemNode::Address))->is_ptr()) )
   1.181 +        set_ctrl(load,blk1);
   1.182 +    }
   1.183 +  }
   1.184 +
   1.185 +  // Found some other Node; must clone it up
   1.186 +#ifndef PRODUCT
   1.187 +  if( PrintOpto && VerifyLoopOptimizations ) {
   1.188 +    tty->print("Cloning up: ");
   1.189 +    n->dump();
   1.190 +  }
   1.191 +#endif
   1.192 +
   1.193 +  // Now actually split-up this guy.  One copy per control path merging.
   1.194 +  Node *phi = PhiNode::make_blank(blk1, n);
   1.195 +  for( uint j = 1; j < blk1->req(); j++ ) {
   1.196 +    Node *x = n->clone();
   1.197 +    if( n->in(0) && n->in(0) == blk1 )
   1.198 +      x->set_req( 0, blk1->in(j) );
   1.199 +    for( uint i = 1; i < n->req(); i++ ) {
   1.200 +      Node *m = n->in(i);
   1.201 +      if( get_ctrl(m) == blk1 ) {
   1.202 +        assert( m->in(0) == blk1, "" );
   1.203 +        x->set_req( i, m->in(j) );
   1.204 +      }
   1.205 +    }
   1.206 +    register_new_node( x, blk1->in(j) );
   1.207 +    phi->init_req( j, x );
   1.208 +  }
   1.209 +  // Announce phi to optimizer
   1.210 +  register_new_node(phi, blk1);
   1.211 +
   1.212 +  // Remove cloned-up value from optimizer; use phi instead
   1.213 +  _igvn.hash_delete(n);
   1.214 +  _igvn.subsume_node( n, phi );
   1.215 +
   1.216 +  // (There used to be a self-recursive call to split_up() here,
   1.217 +  // but it is not needed.  All necessary forward walking is done
   1.218 +  // by do_split_if() below.)
   1.219 +
   1.220 +  return true;
   1.221 +}
   1.222 +
   1.223 +//------------------------------register_new_node------------------------------
   1.224 +void PhaseIdealLoop::register_new_node( Node *n, Node *blk ) {
   1.225 +  _igvn.register_new_node_with_optimizer(n);
   1.226 +  set_ctrl(n, blk);
   1.227 +  IdealLoopTree *loop = get_loop(blk);
   1.228 +  if( !loop->_child )
   1.229 +    loop->_body.push(n);
   1.230 +}
   1.231 +
   1.232 +//------------------------------small_cache------------------------------------
   1.233 +struct small_cache : public Dict {
   1.234 +
   1.235 +  small_cache() : Dict( cmpkey, hashptr ) {}
   1.236 +  Node *probe( Node *use_blk ) { return (Node*)((*this)[use_blk]); }
   1.237 +  void lru_insert( Node *use_blk, Node *new_def ) { Insert(use_blk,new_def); }
   1.238 +};
   1.239 +
   1.240 +//------------------------------spinup-----------------------------------------
   1.241 +// "Spin up" the dominator tree, starting at the use site and stopping when we
   1.242 +// find the post-dominating point.
   1.243 +
   1.244 +// We must be at the merge point which post-dominates 'new_false' and
   1.245 +// 'new_true'.  Figure out which edges into the RegionNode eventually lead up
   1.246 +// to false and which to true.  Put in a PhiNode to merge values; plug in
   1.247 +// the appropriate false-arm or true-arm values.  If some path leads to the
   1.248 +// original IF, then insert a Phi recursively.
   1.249 +Node *PhaseIdealLoop::spinup( Node *iff_dom, Node *new_false, Node *new_true, Node *use_blk, Node *def, small_cache *cache ) {
   1.250 +  if (use_blk->is_top())        // Handle dead uses
   1.251 +    return use_blk;
   1.252 +  Node *prior_n = (Node*)0xdeadbeef;
   1.253 +  Node *n = use_blk;            // Get path input
   1.254 +  assert( use_blk != iff_dom, "" );
   1.255 +  // Here's the "spinup" the dominator tree loop.  Do a cache-check
   1.256 +  // along the way, in case we've come this way before.
   1.257 +  while( n != iff_dom ) {       // Found post-dominating point?
   1.258 +    prior_n = n;
   1.259 +    n = idom(n);                // Search higher
   1.260 +    Node *s = cache->probe( prior_n ); // Check cache
   1.261 +    if( s ) return s;           // Cache hit!
   1.262 +  }
   1.263 +
   1.264 +  Node *phi_post;
   1.265 +  if( prior_n == new_false || prior_n == new_true ) {
   1.266 +    phi_post = def->clone();
   1.267 +    phi_post->set_req(0, prior_n );
   1.268 +    register_new_node(phi_post, prior_n);
   1.269 +  } else {
   1.270 +    // This method handles both control uses (looking for Regions) or data
   1.271 +    // uses (looking for Phis).  If looking for a control use, then we need
   1.272 +    // to insert a Region instead of a Phi; however Regions always exist
   1.273 +    // previously (the hash_find_insert below would always hit) so we can
   1.274 +    // return the existing Region.
   1.275 +    if( def->is_CFG() ) {
   1.276 +      phi_post = prior_n;       // If looking for CFG, return prior
   1.277 +    } else {
   1.278 +      assert( def->is_Phi(), "" );
   1.279 +      assert( prior_n->is_Region(), "must be a post-dominating merge point" );
   1.280 +
   1.281 +      // Need a Phi here
   1.282 +      phi_post = PhiNode::make_blank(prior_n, def);
   1.283 +      // Search for both true and false on all paths till find one.
   1.284 +      for( uint i = 1; i < phi_post->req(); i++ ) // For all paths
   1.285 +        phi_post->init_req( i, spinup( iff_dom, new_false, new_true, prior_n->in(i), def, cache ) );
   1.286 +      Node *t = _igvn.hash_find_insert(phi_post);
   1.287 +      if( t ) {                 // See if we already have this one
   1.288 +        // phi_post will not be used, so kill it
   1.289 +        _igvn.remove_dead_node(phi_post);
   1.290 +        phi_post->destruct();
   1.291 +        phi_post = t;
   1.292 +      } else {
   1.293 +        register_new_node( phi_post, prior_n );
   1.294 +      }
   1.295 +    }
   1.296 +  }
   1.297 +
   1.298 +  // Update cache everywhere
   1.299 +  prior_n = (Node*)0xdeadbeef;  // Reset IDOM walk
   1.300 +  n = use_blk;                  // Get path input
   1.301 +  // Spin-up the idom tree again, basically doing path-compression.
   1.302 +  // Insert cache entries along the way, so that if we ever hit this
   1.303 +  // point in the IDOM tree again we'll stop immediately on a cache hit.
   1.304 +  while( n != iff_dom ) {       // Found post-dominating point?
   1.305 +    prior_n = n;
   1.306 +    n = idom(n);                // Search higher
   1.307 +    cache->lru_insert( prior_n, phi_post ); // Fill cache
   1.308 +  } // End of while not gone high enough
   1.309 +
   1.310 +  return phi_post;
   1.311 +}
   1.312 +
   1.313 +//------------------------------find_use_block---------------------------------
   1.314 +// Find the block a USE is in.  Normally USE's are in the same block as the
   1.315 +// using instruction.  For Phi-USE's, the USE is in the predecessor block
   1.316 +// along the corresponding path.
   1.317 +Node *PhaseIdealLoop::find_use_block( Node *use, Node *def, Node *old_false, Node *new_false, Node *old_true, Node *new_true ) {
   1.318 +  // CFG uses are their own block
   1.319 +  if( use->is_CFG() )
   1.320 +    return use;
   1.321 +
   1.322 +  if( use->is_Phi() ) {         // Phi uses in prior block
   1.323 +    // Grab the first Phi use; there may be many.
   1.324 +    // Each will be handled as a seperate iteration of
   1.325 +    // the "while( phi->outcnt() )" loop.
   1.326 +    uint j;
   1.327 +    for( j = 1; j < use->req(); j++ )
   1.328 +      if( use->in(j) == def )
   1.329 +        break;
   1.330 +    assert( j < use->req(), "def should be among use's inputs" );
   1.331 +    return use->in(0)->in(j);
   1.332 +  }
   1.333 +  // Normal (non-phi) use
   1.334 +  Node *use_blk = get_ctrl(use);
   1.335 +  // Some uses are directly attached to the old (and going away)
   1.336 +  // false and true branches.
   1.337 +  if( use_blk == old_false ) {
   1.338 +    use_blk = new_false;
   1.339 +    set_ctrl(use, new_false);
   1.340 +  }
   1.341 +  if( use_blk == old_true ) {
   1.342 +    use_blk = new_true;
   1.343 +    set_ctrl(use, new_true);
   1.344 +  }
   1.345 +
   1.346 +  if (use_blk == NULL) {        // He's dead, Jim
   1.347 +    _igvn.hash_delete(use);
   1.348 +    _igvn.subsume_node(use, C->top());
   1.349 +  }
   1.350 +
   1.351 +  return use_blk;
   1.352 +}
   1.353 +
   1.354 +//------------------------------handle_use-------------------------------------
   1.355 +// Handle uses of the merge point.  Basically, split-if makes the merge point
   1.356 +// go away so all uses of the merge point must go away as well.  Most block
   1.357 +// local uses have already been split-up, through the merge point.  Uses from
   1.358 +// far below the merge point can't always be split up (e.g., phi-uses are
   1.359 +// pinned) and it makes too much stuff live.  Instead we use a path-based
   1.360 +// solution to move uses down.
   1.361 +//
   1.362 +// If the use is along the pre-split-CFG true branch, then the new use will
   1.363 +// be from the post-split-CFG true merge point.  Vice-versa for the false
   1.364 +// path.  Some uses will be along both paths; then we sink the use to the
   1.365 +// post-dominating location; we may need to insert a Phi there.
   1.366 +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 ) {
   1.367 +
   1.368 +  Node *use_blk = find_use_block(use,def,old_false,new_false,old_true,new_true);
   1.369 +  if( !use_blk ) return;        // He's dead, Jim
   1.370 +
   1.371 +  // Walk up the dominator tree until I hit either the old IfFalse, the old
   1.372 +  // IfTrue or the old If.  Insert Phis where needed.
   1.373 +  Node *new_def = spinup( region_dom, new_false, new_true, use_blk, def, cache );
   1.374 +
   1.375 +  // Found where this USE goes.  Re-point him.
   1.376 +  uint i;
   1.377 +  for( i = 0; i < use->req(); i++ )
   1.378 +    if( use->in(i) == def )
   1.379 +      break;
   1.380 +  assert( i < use->req(), "def should be among use's inputs" );
   1.381 +  _igvn.hash_delete(use);
   1.382 +  use->set_req(i, new_def);
   1.383 +  _igvn._worklist.push(use);
   1.384 +}
   1.385 +
   1.386 +//------------------------------do_split_if------------------------------------
   1.387 +// Found an If getting its condition-code input from a Phi in the same block.
   1.388 +// Split thru the Region.
   1.389 +void PhaseIdealLoop::do_split_if( Node *iff ) {
   1.390 +#ifndef PRODUCT
   1.391 +  if( PrintOpto && VerifyLoopOptimizations )
   1.392 +    tty->print_cr("Split-if");
   1.393 +#endif
   1.394 +  C->set_major_progress();
   1.395 +  Node *region = iff->in(0);
   1.396 +  Node *region_dom = idom(region);
   1.397 +
   1.398 +  // We are going to clone this test (and the control flow with it) up through
   1.399 +  // the incoming merge point.  We need to empty the current basic block.
   1.400 +  // Clone any instructions which must be in this block up through the merge
   1.401 +  // point.
   1.402 +  DUIterator i, j;
   1.403 +  bool progress = true;
   1.404 +  while (progress) {
   1.405 +    progress = false;
   1.406 +    for (i = region->outs(); region->has_out(i); i++) {
   1.407 +      Node* n = region->out(i);
   1.408 +      if( n == region ) continue;
   1.409 +      // The IF to be split is OK.
   1.410 +      if( n == iff ) continue;
   1.411 +      if( !n->is_Phi() ) {      // Found pinned memory op or such
   1.412 +        if (split_up(n, region, iff)) {
   1.413 +          i = region->refresh_out_pos(i);
   1.414 +          progress = true;
   1.415 +        }
   1.416 +        continue;
   1.417 +      }
   1.418 +      assert( n->in(0) == region, "" );
   1.419 +
   1.420 +      // Recursively split up all users of a Phi
   1.421 +      for (j = n->outs(); n->has_out(j); j++) {
   1.422 +        Node* m = n->out(j);
   1.423 +        // If m is dead, throw it away, and declare progress
   1.424 +        if (_nodes[m->_idx] == NULL) {
   1.425 +          _igvn.remove_dead_node(m);
   1.426 +          // fall through
   1.427 +        }
   1.428 +        else if (m != iff && split_up(m, region, iff)) {
   1.429 +          // fall through
   1.430 +        } else {
   1.431 +          continue;
   1.432 +        }
   1.433 +        // Something unpredictable changed.
   1.434 +        // Tell the iterators to refresh themselves, and rerun the loop.
   1.435 +        i = region->refresh_out_pos(i);
   1.436 +        j = region->refresh_out_pos(j);
   1.437 +        progress = true;
   1.438 +      }
   1.439 +    }
   1.440 +  }
   1.441 +
   1.442 +  // Now we have no instructions in the block containing the IF.
   1.443 +  // Split the IF.
   1.444 +  Node *new_iff = split_thru_region( iff, region );
   1.445 +
   1.446 +  // Replace both uses of 'new_iff' with Regions merging True/False
   1.447 +  // paths.  This makes 'new_iff' go dead.
   1.448 +  Node *old_false, *old_true;
   1.449 +  Node *new_false, *new_true;
   1.450 +  for (DUIterator_Last j2min, j2 = iff->last_outs(j2min); j2 >= j2min; --j2) {
   1.451 +    Node *ifp = iff->last_out(j2);
   1.452 +    assert( ifp->Opcode() == Op_IfFalse || ifp->Opcode() == Op_IfTrue, "" );
   1.453 +    ifp->set_req(0, new_iff);
   1.454 +    Node *ifpx = split_thru_region( ifp, region );
   1.455 +
   1.456 +    // Replace 'If' projection of a Region with a Region of
   1.457 +    // 'If' projections.
   1.458 +    ifpx->set_req(0, ifpx);       // A TRUE RegionNode
   1.459 +
   1.460 +    // Setup dominator info
   1.461 +    set_idom(ifpx, region_dom, dom_depth(region_dom) + 1);
   1.462 +
   1.463 +    // Check for splitting loop tails
   1.464 +    if( get_loop(iff)->tail() == ifp )
   1.465 +      get_loop(iff)->_tail = ifpx;
   1.466 +
   1.467 +    // Replace in the graph with lazy-update mechanism
   1.468 +    new_iff->set_req(0, new_iff); // hook self so it does not go dead
   1.469 +    lazy_replace_proj( ifp, ifpx );
   1.470 +    new_iff->set_req(0, region);
   1.471 +
   1.472 +    // Record bits for later xforms
   1.473 +    if( ifp->Opcode() == Op_IfFalse ) {
   1.474 +      old_false = ifp;
   1.475 +      new_false = ifpx;
   1.476 +    } else {
   1.477 +      old_true = ifp;
   1.478 +      new_true = ifpx;
   1.479 +    }
   1.480 +  }
   1.481 +  _igvn.remove_dead_node(new_iff);
   1.482 +  // Lazy replace IDOM info with the region's dominator
   1.483 +  lazy_replace( iff, region_dom );
   1.484 +
   1.485 +  // Now make the original merge point go dead, by handling all its uses.
   1.486 +  small_cache region_cache;
   1.487 +  // Preload some control flow in region-cache
   1.488 +  region_cache.lru_insert( new_false, new_false );
   1.489 +  region_cache.lru_insert( new_true , new_true  );
   1.490 +  // Now handle all uses of the splitting block
   1.491 +  for (DUIterator_Last kmin, k = region->last_outs(kmin); k >= kmin; --k) {
   1.492 +    Node* phi = region->last_out(k);
   1.493 +    if( !phi->in(0) ) {         // Dead phi?  Remove it
   1.494 +      _igvn.remove_dead_node(phi);
   1.495 +      continue;
   1.496 +    }
   1.497 +    assert( phi->in(0) == region, "" );
   1.498 +    if( phi == region ) {       // Found the self-reference
   1.499 +      phi->set_req(0, NULL);
   1.500 +      continue;                 // Break the self-cycle
   1.501 +    }
   1.502 +    // Expected common case: Phi hanging off of Region
   1.503 +    if( phi->is_Phi() ) {
   1.504 +      // Need a per-def cache.  Phi represents a def, so make a cache
   1.505 +      small_cache phi_cache;
   1.506 +
   1.507 +      // Inspect all Phi uses to make the Phi go dead
   1.508 +      for (DUIterator_Last lmin, l = phi->last_outs(lmin); l >= lmin; --l) {
   1.509 +        Node* use = phi->last_out(l);
   1.510 +        // Compute the new DEF for this USE.  New DEF depends on the path
   1.511 +        // taken from the original DEF to the USE.  The new DEF may be some
   1.512 +        // collection of PHI's merging values from different paths.  The Phis
   1.513 +        // inserted depend only on the location of the USE.  We use a
   1.514 +        // 2-element cache to handle multiple uses from the same block.
   1.515 +        handle_use( use, phi, &phi_cache, region_dom, new_false, new_true, old_false, old_true );
   1.516 +      } // End of while phi has uses
   1.517 +
   1.518 +      // Because handle_use might relocate region->_out,
   1.519 +      // we must refresh the iterator.
   1.520 +      k = region->last_outs(kmin);
   1.521 +
   1.522 +      // Remove the dead Phi
   1.523 +      _igvn.remove_dead_node( phi );
   1.524 +
   1.525 +    } else {
   1.526 +      // Random memory op guarded by Region.  Compute new DEF for USE.
   1.527 +      handle_use( phi, region, &region_cache, region_dom, new_false, new_true, old_false, old_true );
   1.528 +    }
   1.529 +
   1.530 +  } // End of while merge point has phis
   1.531 +
   1.532 +  // Any leftover bits in the splitting block must not have depended on local
   1.533 +  // Phi inputs (these have already been split-up).  Hence it's safe to hoist
   1.534 +  // these guys to the dominating point.
   1.535 +  lazy_replace( region, region_dom );
   1.536 +#ifndef PRODUCT
   1.537 +  if( VerifyLoopOptimizations ) verify();
   1.538 +#endif
   1.539 +}

mercurial