< prev index next >

src/share/vm/opto/loopopts.cpp

Print this page




  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/addnode.hpp"
  28 #include "opto/connode.hpp"
  29 #include "opto/divnode.hpp"
  30 #include "opto/loopnode.hpp"
  31 #include "opto/matcher.hpp"
  32 #include "opto/mulnode.hpp"
  33 #include "opto/rootnode.hpp"
  34 #include "opto/subnode.hpp"



  35 
  36 //=============================================================================
  37 //------------------------------split_thru_phi---------------------------------
  38 // Split Node 'n' through merge point if there is enough win.
  39 Node *PhaseIdealLoop::split_thru_phi( Node *n, Node *region, int policy ) {
  40   if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) {
  41     // ConvI2L may have type information on it which is unsafe to push up
  42     // so disable this for now
  43     return NULL;
  44   }
  45 
  46   // Splitting range check CastIIs through a loop induction Phi can
  47   // cause new Phis to be created that are left unrelated to the loop
  48   // induction Phi and prevent optimizations (vectorization)
  49   if (n->Opcode() == Op_CastII && n->as_CastII()->has_range_check() &&
  50       region->is_CountedLoop() && n->in(1) == region->as_CountedLoop()->phi()) {
  51     return NULL;
  52   }
  53 
  54   int wins = 0;


 100       // irreducible loop may not be indicated by an affirmative is_Loop());
 101       // therefore, the only top we can split thru a phi is on a backedge of
 102       // a loop.
 103       singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
 104     }
 105 
 106     if (singleton) {
 107       wins++;
 108       x = ((PhaseGVN&)_igvn).makecon(t);
 109     } else {
 110       // We now call Identity to try to simplify the cloned node.
 111       // Note that some Identity methods call phase->type(this).
 112       // Make sure that the type array is big enough for
 113       // our new node, even though we may throw the node away.
 114       // (Note: This tweaking with igvn only works because x is a new node.)
 115       _igvn.set_type(x, t);
 116       // If x is a TypeNode, capture any more-precise type permanently into Node
 117       // otherwise it will be not updated during igvn->transform since
 118       // igvn->type(x) is set to x->Value() already.
 119       x->raise_bottom_type(t);

 120       Node *y = x->Identity(&_igvn);
 121       if (y != x) {
 122         wins++;
 123         x = y;
 124       } else {
 125         y = _igvn.hash_find(x);
 126         if (y) {
 127           wins++;
 128           x = y;
 129         } else {
 130           // Else x is a new node we are keeping
 131           // We do not need register_new_node_with_optimizer
 132           // because set_type has already been called.
 133           _igvn._worklist.push(x);
 134         }
 135       }



 136     }
 137     if (x != the_clone && the_clone != NULL)
 138       _igvn.remove_dead_node(the_clone);
 139     phi->set_req( i, x );
 140   }
 141   // Too few wins?
 142   if (wins <= policy) {
 143     _igvn.remove_dead_node(phi);
 144     return NULL;
 145   }
 146 
 147   // Record Phi
 148   register_new_node( phi, region );
 149 
 150   for (uint i2 = 1; i2 < phi->req(); i2++) {
 151     Node *x = phi->in(i2);
 152     // If we commoned up the cloned 'x' with another existing Node,
 153     // the existing Node picks up a new use.  We need to make the
 154     // existing Node occur higher up so it dominates its uses.
 155     Node *old_ctrl;


 287     if( phi->is_Phi() && phi->in(0) == n_ctrl )
 288       break;
 289   }
 290   if( i >= n->req() )
 291     return NULL;                // No Phi inputs; nowhere to clone thru
 292 
 293   // Check for inputs created between 'n' and the Phi input.  These
 294   // must split as well; they have already been given the chance
 295   // (courtesy of a post-order visit) and since they did not we must
 296   // recover the 'cost' of splitting them by being very profitable
 297   // when splitting 'n'.  Since this is unlikely we simply give up.
 298   for( i = 1; i < n->req(); i++ ) {
 299     Node *m = n->in(i);
 300     if( get_ctrl(m) == n_ctrl && !m->is_Phi() ) {
 301       // We allow the special case of AddP's with no local inputs.
 302       // This allows us to split-up address expressions.
 303       if (m->is_AddP() &&
 304           get_ctrl(m->in(2)) != n_ctrl &&
 305           get_ctrl(m->in(3)) != n_ctrl) {
 306         // Move the AddP up to dominating point
 307         set_ctrl_and_loop(m, find_non_split_ctrl(idom(n_ctrl)));

 308         continue;
 309       }
 310       return NULL;
 311     }
 312     assert(n->is_Phi() || m->is_Phi() || is_dominator(get_ctrl(m), n_ctrl), "m has strange control");
 313   }
 314 
 315   return n_ctrl;
 316 }
 317 
 318 //------------------------------remix_address_expressions----------------------
 319 // Rework addressing expressions to get the most loop-invariant stuff
 320 // moved out.  We'd like to do all associative operators, but it's especially
 321 // important (common) to do address expressions.
 322 Node *PhaseIdealLoop::remix_address_expressions( Node *n ) {
 323   if (!has_ctrl(n))  return NULL;
 324   Node *n_ctrl = get_ctrl(n);
 325   IdealLoopTree *n_loop = get_loop(n_ctrl);
 326 
 327   // See if 'n' mixes loop-varying and loop-invariant inputs and


 725   if (n_blk->is_CountedLoop()) {
 726     IdealLoopTree *lp = get_loop(n_blk);
 727     if (lp && lp->_rce_candidate) {
 728       return n;
 729     }
 730   }
 731 
 732   // Use same limit as split_if_with_blocks_post
 733   if( C->unique() > 35000 ) return n; // Method too big
 734 
 735   // Split 'n' through the merge point if it is profitable
 736   Node *phi = split_thru_phi( n, n_blk, policy );
 737   if (!phi) return n;
 738 
 739   // Found a Phi to split thru!
 740   // Replace 'n' with the new phi
 741   _igvn.replace_node( n, phi );
 742   // Moved a load around the loop, 'en-registering' something.
 743   if (n_blk->is_Loop() && n->is_Load() &&
 744       !phi->in(LoopNode::LoopBackControl)->is_Load())





 745     C->set_major_progress();
 746 
 747   return phi;
 748 }
 749 
 750 static bool merge_point_too_heavy(Compile* C, Node* region) {
 751   // Bail out if the region and its phis have too many users.
 752   int weight = 0;
 753   for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
 754     weight += region->fast_out(i)->outcnt();
 755   }
 756   int nodes_left = C->max_node_limit() - C->live_nodes();
 757   if (weight * 8 > nodes_left) {
 758 #ifndef PRODUCT
 759     if (PrintOpto)
 760       tty->print_cr("*** Split-if bails out:  %d nodes, region weight %d", C->unique(), weight);
 761 #endif
 762     return true;
 763   } else {
 764     return false;




  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/addnode.hpp"
  28 #include "opto/connode.hpp"
  29 #include "opto/divnode.hpp"
  30 #include "opto/loopnode.hpp"
  31 #include "opto/matcher.hpp"
  32 #include "opto/mulnode.hpp"
  33 #include "opto/rootnode.hpp"
  34 #include "opto/subnode.hpp"
  35 #if INCLUDE_ALL_GCS
  36 #include "gc_implementation/shenandoah/shenandoahSupport.hpp"
  37 #endif
  38 
  39 //=============================================================================
  40 //------------------------------split_thru_phi---------------------------------
  41 // Split Node 'n' through merge point if there is enough win.
  42 Node *PhaseIdealLoop::split_thru_phi( Node *n, Node *region, int policy ) {
  43   if (n->Opcode() == Op_ConvI2L && n->bottom_type() != TypeLong::LONG) {
  44     // ConvI2L may have type information on it which is unsafe to push up
  45     // so disable this for now
  46     return NULL;
  47   }
  48 
  49   // Splitting range check CastIIs through a loop induction Phi can
  50   // cause new Phis to be created that are left unrelated to the loop
  51   // induction Phi and prevent optimizations (vectorization)
  52   if (n->Opcode() == Op_CastII && n->as_CastII()->has_range_check() &&
  53       region->is_CountedLoop() && n->in(1) == region->as_CountedLoop()->phi()) {
  54     return NULL;
  55   }
  56 
  57   int wins = 0;


 103       // irreducible loop may not be indicated by an affirmative is_Loop());
 104       // therefore, the only top we can split thru a phi is on a backedge of
 105       // a loop.
 106       singleton &= region->is_Loop() && (i != LoopNode::EntryControl);
 107     }
 108 
 109     if (singleton) {
 110       wins++;
 111       x = ((PhaseGVN&)_igvn).makecon(t);
 112     } else {
 113       // We now call Identity to try to simplify the cloned node.
 114       // Note that some Identity methods call phase->type(this).
 115       // Make sure that the type array is big enough for
 116       // our new node, even though we may throw the node away.
 117       // (Note: This tweaking with igvn only works because x is a new node.)
 118       _igvn.set_type(x, t);
 119       // If x is a TypeNode, capture any more-precise type permanently into Node
 120       // otherwise it will be not updated during igvn->transform since
 121       // igvn->type(x) is set to x->Value() already.
 122       x->raise_bottom_type(t);
 123       if (x->Opcode() != Op_ShenandoahLoadReferenceBarrier) {
 124       Node *y = x->Identity(&_igvn);
 125       if (y != x) {
 126         wins++;
 127         x = y;
 128       } else {
 129         y = _igvn.hash_find(x);
 130         if (y) {
 131           wins++;
 132           x = y;
 133         } else {
 134           // Else x is a new node we are keeping
 135           // We do not need register_new_node_with_optimizer
 136           // because set_type has already been called.
 137           _igvn._worklist.push(x);
 138         }
 139       }
 140       } else {
 141         _igvn._worklist.push(x);
 142       }
 143     }
 144     if (x != the_clone && the_clone != NULL)
 145       _igvn.remove_dead_node(the_clone);
 146     phi->set_req( i, x );
 147   }
 148   // Too few wins?
 149   if (wins <= policy) {
 150     _igvn.remove_dead_node(phi);
 151     return NULL;
 152   }
 153 
 154   // Record Phi
 155   register_new_node( phi, region );
 156 
 157   for (uint i2 = 1; i2 < phi->req(); i2++) {
 158     Node *x = phi->in(i2);
 159     // If we commoned up the cloned 'x' with another existing Node,
 160     // the existing Node picks up a new use.  We need to make the
 161     // existing Node occur higher up so it dominates its uses.
 162     Node *old_ctrl;


 294     if( phi->is_Phi() && phi->in(0) == n_ctrl )
 295       break;
 296   }
 297   if( i >= n->req() )
 298     return NULL;                // No Phi inputs; nowhere to clone thru
 299 
 300   // Check for inputs created between 'n' and the Phi input.  These
 301   // must split as well; they have already been given the chance
 302   // (courtesy of a post-order visit) and since they did not we must
 303   // recover the 'cost' of splitting them by being very profitable
 304   // when splitting 'n'.  Since this is unlikely we simply give up.
 305   for( i = 1; i < n->req(); i++ ) {
 306     Node *m = n->in(i);
 307     if( get_ctrl(m) == n_ctrl && !m->is_Phi() ) {
 308       // We allow the special case of AddP's with no local inputs.
 309       // This allows us to split-up address expressions.
 310       if (m->is_AddP() &&
 311           get_ctrl(m->in(2)) != n_ctrl &&
 312           get_ctrl(m->in(3)) != n_ctrl) {
 313         // Move the AddP up to dominating point
 314         Node* c = find_non_split_ctrl(idom(n_ctrl));
 315         set_ctrl_and_loop(m, c);
 316         continue;
 317       }
 318       return NULL;
 319     }
 320     assert(n->is_Phi() || m->is_Phi() || is_dominator(get_ctrl(m), n_ctrl), "m has strange control");
 321   }
 322 
 323   return n_ctrl;
 324 }
 325 
 326 //------------------------------remix_address_expressions----------------------
 327 // Rework addressing expressions to get the most loop-invariant stuff
 328 // moved out.  We'd like to do all associative operators, but it's especially
 329 // important (common) to do address expressions.
 330 Node *PhaseIdealLoop::remix_address_expressions( Node *n ) {
 331   if (!has_ctrl(n))  return NULL;
 332   Node *n_ctrl = get_ctrl(n);
 333   IdealLoopTree *n_loop = get_loop(n_ctrl);
 334 
 335   // See if 'n' mixes loop-varying and loop-invariant inputs and


 733   if (n_blk->is_CountedLoop()) {
 734     IdealLoopTree *lp = get_loop(n_blk);
 735     if (lp && lp->_rce_candidate) {
 736       return n;
 737     }
 738   }
 739 
 740   // Use same limit as split_if_with_blocks_post
 741   if( C->unique() > 35000 ) return n; // Method too big
 742 
 743   // Split 'n' through the merge point if it is profitable
 744   Node *phi = split_thru_phi( n, n_blk, policy );
 745   if (!phi) return n;
 746 
 747   // Found a Phi to split thru!
 748   // Replace 'n' with the new phi
 749   _igvn.replace_node( n, phi );
 750   // Moved a load around the loop, 'en-registering' something.
 751   if (n_blk->is_Loop() && n->is_Load() &&
 752       !phi->in(LoopNode::LoopBackControl)->is_Load())
 753     C->set_major_progress();
 754 
 755   // Moved a barrier around the loop, 'en-registering' something.
 756   if (n_blk->is_Loop() && n->Opcode() == Op_ShenandoahLoadReferenceBarrier &&
 757       phi->in(LoopNode::LoopBackControl)->Opcode() != Op_ShenandoahLoadReferenceBarrier)
 758     C->set_major_progress();
 759 
 760   return phi;
 761 }
 762 
 763 static bool merge_point_too_heavy(Compile* C, Node* region) {
 764   // Bail out if the region and its phis have too many users.
 765   int weight = 0;
 766   for (DUIterator_Fast imax, i = region->fast_outs(imax); i < imax; i++) {
 767     weight += region->fast_out(i)->outcnt();
 768   }
 769   int nodes_left = C->max_node_limit() - C->live_nodes();
 770   if (weight * 8 > nodes_left) {
 771 #ifndef PRODUCT
 772     if (PrintOpto)
 773       tty->print_cr("*** Split-if bails out:  %d nodes, region weight %d", C->unique(), weight);
 774 #endif
 775     return true;
 776   } else {
 777     return false;


< prev index next >