src/share/vm/opto/loopnode.cpp

changeset 1607
b2b6a9bf6238
parent 1518
8b22f86d1740
child 1907
c18cbe5936b8
     1.1 --- a/src/share/vm/opto/loopnode.cpp	Sat Jan 09 00:59:35 2010 -0800
     1.2 +++ b/src/share/vm/opto/loopnode.cpp	Tue Jan 12 14:37:35 2010 -0800
     1.3 @@ -1420,11 +1420,57 @@
     1.4    }
     1.5  }
     1.6  
     1.7 +//---------------------collect_potentially_useful_predicates-----------------------
     1.8 +// Helper function to collect potentially useful predicates to prevent them from
     1.9 +// being eliminated by PhaseIdealLoop::eliminate_useless_predicates
    1.10 +void PhaseIdealLoop::collect_potentially_useful_predicates(
    1.11 +                         IdealLoopTree * loop, Unique_Node_List &useful_predicates) {
    1.12 +  if (loop->_child) { // child
    1.13 +    collect_potentially_useful_predicates(loop->_child, useful_predicates);
    1.14 +  }
    1.15 +
    1.16 +  // self (only loops that we can apply loop predication may use their predicates)
    1.17 +  if (loop->_head->is_Loop()     &&
    1.18 +      !loop->_irreducible        &&
    1.19 +      !loop->tail()->is_top()) {
    1.20 +    LoopNode *lpn  = loop->_head->as_Loop();
    1.21 +    Node* entry = lpn->in(LoopNode::EntryControl);
    1.22 +    ProjNode *predicate_proj = find_predicate_insertion_point(entry);
    1.23 +    if (predicate_proj != NULL ) { // right pattern that can be used by loop predication
    1.24 +      assert(entry->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
    1.25 +      useful_predicates.push(entry->in(0)->in(1)->in(1)); // good one
    1.26 +    }
    1.27 +  }
    1.28 +
    1.29 +  if ( loop->_next ) { // sibling
    1.30 +    collect_potentially_useful_predicates(loop->_next, useful_predicates);
    1.31 +  }
    1.32 +}
    1.33 +
    1.34 +//------------------------eliminate_useless_predicates-----------------------------
    1.35 +// Eliminate all inserted predicates if they could not be used by loop predication.
    1.36 +void PhaseIdealLoop::eliminate_useless_predicates() {
    1.37 +  if (C->predicate_count() == 0) return; // no predicate left
    1.38 +
    1.39 +  Unique_Node_List useful_predicates; // to store useful predicates
    1.40 +  if (C->has_loops()) {
    1.41 +    collect_potentially_useful_predicates(_ltree_root->_child, useful_predicates);
    1.42 +  }
    1.43 +
    1.44 +  for (int i = C->predicate_count(); i > 0; i--) {
    1.45 +     Node * n = C->predicate_opaque1_node(i-1);
    1.46 +     assert(n->Opcode() == Op_Opaque1, "must be");
    1.47 +     if (!useful_predicates.member(n)) { // not in the useful list
    1.48 +       _igvn.replace_node(n, n->in(1));
    1.49 +     }
    1.50 +  }
    1.51 +}
    1.52 +
    1.53  //=============================================================================
    1.54  //----------------------------build_and_optimize-------------------------------
    1.55  // Create a PhaseLoop.  Build the ideal Loop tree.  Map each Ideal Node to
    1.56  // its corresponding LoopNode.  If 'optimize' is true, do some loop cleanups.
    1.57 -void PhaseIdealLoop::build_and_optimize(bool do_split_ifs) {
    1.58 +void PhaseIdealLoop::build_and_optimize(bool do_split_ifs, bool do_loop_pred) {
    1.59    int old_progress = C->major_progress();
    1.60  
    1.61    // Reset major-progress flag for the driver's heuristics
    1.62 @@ -1577,6 +1623,12 @@
    1.63      return;
    1.64    }
    1.65  
    1.66 +  // some parser-inserted loop predicates could never be used by loop
    1.67 +  // predication. Eliminate them before loop optimization
    1.68 +  if (UseLoopPredicate) {
    1.69 +    eliminate_useless_predicates();
    1.70 +  }
    1.71 +
    1.72    // clear out the dead code
    1.73    while(_deadlist.size()) {
    1.74      _igvn.remove_globally_dead_node(_deadlist.pop());
    1.75 @@ -1603,7 +1655,7 @@
    1.76        // Because RCE opportunities can be masked by split_thru_phi,
    1.77        // look for RCE candidates and inhibit split_thru_phi
    1.78        // on just their loop-phi's for this pass of loop opts
    1.79 -      if( SplitIfBlocks && do_split_ifs ) {
    1.80 +      if (SplitIfBlocks && do_split_ifs) {
    1.81          if (lpt->policy_range_check(this)) {
    1.82            lpt->_rce_candidate = 1; // = true
    1.83          }
    1.84 @@ -1619,12 +1671,17 @@
    1.85      NOT_PRODUCT( if( VerifyLoopOptimizations ) verify(); );
    1.86    }
    1.87  
    1.88 +  // Perform loop predication before iteration splitting
    1.89 +  if (do_loop_pred && C->has_loops() && !C->major_progress()) {
    1.90 +    _ltree_root->_child->loop_predication(this);
    1.91 +  }
    1.92 +
    1.93    // Perform iteration-splitting on inner loops.  Split iterations to avoid
    1.94    // range checks or one-shot null checks.
    1.95  
    1.96    // If split-if's didn't hack the graph too bad (no CFG changes)
    1.97    // then do loop opts.
    1.98 -  if( C->has_loops() && !C->major_progress() ) {
    1.99 +  if (C->has_loops() && !C->major_progress()) {
   1.100      memset( worklist.adr(), 0, worklist.Size()*sizeof(Node*) );
   1.101      _ltree_root->_child->iteration_split( this, worklist );
   1.102      // No verify after peeling!  GCM has hoisted code out of the loop.
   1.103 @@ -1636,7 +1693,7 @@
   1.104    // Do verify graph edges in any case
   1.105    NOT_PRODUCT( C->verify_graph_edges(); );
   1.106  
   1.107 -  if( !do_split_ifs ) {
   1.108 +  if (!do_split_ifs) {
   1.109      // We saw major progress in Split-If to get here.  We forced a
   1.110      // pass with unrolling and not split-if, however more split-if's
   1.111      // might make progress.  If the unrolling didn't make progress
   1.112 @@ -2763,6 +2820,22 @@
   1.113    Node *legal = LCA;            // Walk 'legal' up the IDOM chain
   1.114    Node *least = legal;          // Best legal position so far
   1.115    while( early != legal ) {     // While not at earliest legal
   1.116 +#ifdef ASSERT
   1.117 +    if (legal->is_Start() && !early->is_Root()) {
   1.118 +      // Bad graph. Print idom path and fail.
   1.119 +      tty->print_cr( "Bad graph detected in build_loop_late");
   1.120 +      tty->print("n: ");n->dump(); tty->cr();
   1.121 +      tty->print("early: ");early->dump(); tty->cr();
   1.122 +      int ct = 0;
   1.123 +      Node *dbg_legal = LCA;
   1.124 +      while(!dbg_legal->is_Start() && ct < 100) {
   1.125 +        tty->print("idom[%d] ",ct); dbg_legal->dump(); tty->cr();
   1.126 +        ct++;
   1.127 +        dbg_legal = idom(dbg_legal);
   1.128 +      }
   1.129 +      assert(false, "Bad graph detected in build_loop_late");
   1.130 +    }
   1.131 +#endif
   1.132      // Find least loop nesting depth
   1.133      legal = idom(legal);        // Bump up the IDOM tree
   1.134      // Check for lower nesting depth

mercurial