< prev index next >

src/hotspot/share/opto/loopnode.cpp

Print this page
rev 50110 : 8203215: IdealLoopTree::split_outer_loop leaves phi-nodes with only one input
Summary: Make sure the phis are transformed
Reviewed-by:


1786   Node *outer = new LoopNode( ctl, _head->in(outer_idx) );
1787   outer = igvn.register_new_node_with_optimizer(outer, _head);
1788   phase->set_created_loop_node();
1789 
1790   // Outermost loop falls into '_head' loop
1791   _head->set_req(LoopNode::EntryControl, outer);
1792   _head->del_req(outer_idx);
1793   // Split all the Phis up between '_head' loop and 'outer' loop.
1794   for (DUIterator_Fast jmax, j = _head->fast_outs(jmax); j < jmax; j++) {
1795     Node *out = _head->fast_out(j);
1796     if( out->is_Phi() ) {
1797       PhiNode *old_phi = out->as_Phi();
1798       assert( old_phi->region() == _head, "" );
1799       Node *phi = PhiNode::make_blank(outer, old_phi);
1800       phi->init_req(LoopNode::EntryControl,    old_phi->in(LoopNode::EntryControl));
1801       phi->init_req(LoopNode::LoopBackControl, old_phi->in(outer_idx));
1802       phi = igvn.register_new_node_with_optimizer(phi, old_phi);
1803       // Make old Phi point to new Phi on the fall-in path
1804       igvn.replace_input_of(old_phi, LoopNode::EntryControl, phi);
1805       old_phi->del_req(outer_idx);

1806     }
1807   }
1808 
1809   // Use the new loop head instead of the old shared one
1810   _head = outer;
1811   phase->set_loop(_head, this);
1812 }
1813 
1814 //------------------------------fix_parent-------------------------------------
1815 static void fix_parent( IdealLoopTree *loop, IdealLoopTree *parent ) {
1816   loop->_parent = parent;
1817   if( loop->_child ) fix_parent( loop->_child, loop   );
1818   if( loop->_next  ) fix_parent( loop->_next , parent );
1819 }
1820 
1821 //------------------------------estimate_path_freq-----------------------------
1822 static float estimate_path_freq( Node *n ) {
1823   // Try to extract some path frequency info
1824   IfNode *iff;
1825   for( int i = 0; i < 50; i++ ) { // Skip through a bunch of uncommon tests


2019     }
2020   }
2021   assert( !phase->is_member( this, _head->in(1) ), "left edge is fall-in" );
2022   assert(  phase->is_member( this, _head->in(2) ), "right edge is loop" );
2023 
2024   // If I am a shared header (multiple backedges), peel off the many
2025   // backedges into a private merge point and use the merge point as
2026   // the one true backedge.
2027   if( _head->req() > 3 ) {
2028     // Merge the many backedges into a single backedge but leave
2029     // the hottest backedge as separate edge for the following peel.
2030     merge_many_backedges( phase );
2031     result = true;
2032   }
2033 
2034   // If I have one hot backedge, peel off myself loop.
2035   // I better be the outermost loop.
2036   if (_head->req() > 3 && !_irreducible) {
2037     split_outer_loop( phase );
2038     result = true;
2039 
2040   } else if (!_head->is_Loop() && !_irreducible) {
2041     // Make a new LoopNode to replace the old loop head
2042     Node *l = new LoopNode( _head->in(1), _head->in(2) );
2043     l = igvn.register_new_node_with_optimizer(l, _head);
2044     phase->set_created_loop_node();
2045     // Go ahead and replace _head
2046     phase->_igvn.replace_node( _head, l );
2047     _head = l;
2048     phase->set_loop(_head, this);
2049   }
2050 
2051   // Now recursively beautify nested loops
2052   if( _child ) result |= _child->beautify_loops( phase );
2053   if( _next  ) result |= _next ->beautify_loops( phase );
2054   return result;
2055 }
2056 
2057 //------------------------------allpaths_check_safepts----------------------------
2058 // Allpaths backwards scan from loop tail, terminating each path at first safepoint
2059 // encountered.  Helper for check_safepts.


2697     }
2698     return;
2699   }
2700 
2701   // Nothing to do, so get out
2702   bool stop_early = !C->has_loops() && !skip_loop_opts && !do_split_ifs && !_verify_me && !_verify_only;
2703   bool do_expensive_nodes = C->should_optimize_expensive_nodes(_igvn);
2704   if (stop_early && !do_expensive_nodes) {
2705     _igvn.optimize();           // Cleanup NeverBranches
2706     return;
2707   }
2708 
2709   // Set loop nesting depth
2710   _ltree_root->set_nest( 0 );
2711 
2712   // Split shared headers and insert loop landing pads.
2713   // Do not bother doing this on the Root loop of course.
2714   if( !_verify_me && !_verify_only && _ltree_root->_child ) {
2715     C->print_method(PHASE_BEFORE_BEAUTIFY_LOOPS, 3);
2716     if( _ltree_root->_child->beautify_loops( this ) ) {




2717       // Re-build loop tree!
2718       _ltree_root->_child = NULL;
2719       _nodes.clear();
2720       reallocate_preorders();
2721       build_loop_tree();

2722       // Check for bailout, and return
2723       if (C->failing()) {
2724         return;
2725       }
2726       // Reset loop nesting depth
2727       _ltree_root->set_nest( 0 );
2728 
2729       C->print_method(PHASE_AFTER_BEAUTIFY_LOOPS, 3);
2730     }
2731   }
2732 
2733   // Build Dominators for elision of NULL checks & loop finding.
2734   // Since nodes do not have a slot for immediate dominator, make
2735   // a persistent side array for that info indexed on node->_idx.
2736   _idom_size = C->unique();
2737   _idom      = NEW_RESOURCE_ARRAY( Node*, _idom_size );
2738   _dom_depth = NEW_RESOURCE_ARRAY( uint,  _idom_size );
2739   _dom_stk   = NULL; // Allocated on demand in recompute_dom_depth
2740   memset( _dom_depth, 0, _idom_size * sizeof(uint) );
2741 




1786   Node *outer = new LoopNode( ctl, _head->in(outer_idx) );
1787   outer = igvn.register_new_node_with_optimizer(outer, _head);
1788   phase->set_created_loop_node();
1789 
1790   // Outermost loop falls into '_head' loop
1791   _head->set_req(LoopNode::EntryControl, outer);
1792   _head->del_req(outer_idx);
1793   // Split all the Phis up between '_head' loop and 'outer' loop.
1794   for (DUIterator_Fast jmax, j = _head->fast_outs(jmax); j < jmax; j++) {
1795     Node *out = _head->fast_out(j);
1796     if( out->is_Phi() ) {
1797       PhiNode *old_phi = out->as_Phi();
1798       assert( old_phi->region() == _head, "" );
1799       Node *phi = PhiNode::make_blank(outer, old_phi);
1800       phi->init_req(LoopNode::EntryControl,    old_phi->in(LoopNode::EntryControl));
1801       phi->init_req(LoopNode::LoopBackControl, old_phi->in(outer_idx));
1802       phi = igvn.register_new_node_with_optimizer(phi, old_phi);
1803       // Make old Phi point to new Phi on the fall-in path
1804       igvn.replace_input_of(old_phi, LoopNode::EntryControl, phi);
1805       old_phi->del_req(outer_idx);
1806       igvn.rehash_node_delayed(old_phi);
1807     }
1808   }
1809 
1810   // Use the new loop head instead of the old shared one
1811   _head = outer;
1812   phase->set_loop(_head, this);
1813 }
1814 
1815 //------------------------------fix_parent-------------------------------------
1816 static void fix_parent( IdealLoopTree *loop, IdealLoopTree *parent ) {
1817   loop->_parent = parent;
1818   if( loop->_child ) fix_parent( loop->_child, loop   );
1819   if( loop->_next  ) fix_parent( loop->_next , parent );
1820 }
1821 
1822 //------------------------------estimate_path_freq-----------------------------
1823 static float estimate_path_freq( Node *n ) {
1824   // Try to extract some path frequency info
1825   IfNode *iff;
1826   for( int i = 0; i < 50; i++ ) { // Skip through a bunch of uncommon tests


2020     }
2021   }
2022   assert( !phase->is_member( this, _head->in(1) ), "left edge is fall-in" );
2023   assert(  phase->is_member( this, _head->in(2) ), "right edge is loop" );
2024 
2025   // If I am a shared header (multiple backedges), peel off the many
2026   // backedges into a private merge point and use the merge point as
2027   // the one true backedge.
2028   if( _head->req() > 3 ) {
2029     // Merge the many backedges into a single backedge but leave
2030     // the hottest backedge as separate edge for the following peel.
2031     merge_many_backedges( phase );
2032     result = true;
2033   }
2034 
2035   // If I have one hot backedge, peel off myself loop.
2036   // I better be the outermost loop.
2037   if (_head->req() > 3 && !_irreducible) {
2038     split_outer_loop( phase );
2039     result = true;

2040   } else if (!_head->is_Loop() && !_irreducible) {
2041     // Make a new LoopNode to replace the old loop head
2042     Node *l = new LoopNode( _head->in(1), _head->in(2) );
2043     l = igvn.register_new_node_with_optimizer(l, _head);
2044     phase->set_created_loop_node();
2045     // Go ahead and replace _head
2046     phase->_igvn.replace_node( _head, l );
2047     _head = l;
2048     phase->set_loop(_head, this);
2049   }
2050 
2051   // Now recursively beautify nested loops
2052   if( _child ) result |= _child->beautify_loops( phase );
2053   if( _next  ) result |= _next ->beautify_loops( phase );
2054   return result;
2055 }
2056 
2057 //------------------------------allpaths_check_safepts----------------------------
2058 // Allpaths backwards scan from loop tail, terminating each path at first safepoint
2059 // encountered.  Helper for check_safepts.


2697     }
2698     return;
2699   }
2700 
2701   // Nothing to do, so get out
2702   bool stop_early = !C->has_loops() && !skip_loop_opts && !do_split_ifs && !_verify_me && !_verify_only;
2703   bool do_expensive_nodes = C->should_optimize_expensive_nodes(_igvn);
2704   if (stop_early && !do_expensive_nodes) {
2705     _igvn.optimize();           // Cleanup NeverBranches
2706     return;
2707   }
2708 
2709   // Set loop nesting depth
2710   _ltree_root->set_nest( 0 );
2711 
2712   // Split shared headers and insert loop landing pads.
2713   // Do not bother doing this on the Root loop of course.
2714   if( !_verify_me && !_verify_only && _ltree_root->_child ) {
2715     C->print_method(PHASE_BEFORE_BEAUTIFY_LOOPS, 3);
2716     if( _ltree_root->_child->beautify_loops( this ) ) {
2717       // IdealLoopTree::split_outer_loop may produce phi-nodes with a single in edge.
2718       // Transform them away.
2719       _igvn.optimize();
2720 
2721       // Re-build loop tree!
2722       _ltree_root->_child = NULL;
2723       _nodes.clear();
2724       reallocate_preorders();
2725       build_loop_tree();
2726 
2727       // Check for bailout, and return
2728       if (C->failing()) {
2729         return;
2730       }
2731       // Reset loop nesting depth
2732       _ltree_root->set_nest( 0 );
2733 
2734       C->print_method(PHASE_AFTER_BEAUTIFY_LOOPS, 3);
2735     }
2736   }
2737 
2738   // Build Dominators for elision of NULL checks & loop finding.
2739   // Since nodes do not have a slot for immediate dominator, make
2740   // a persistent side array for that info indexed on node->_idx.
2741   _idom_size = C->unique();
2742   _idom      = NEW_RESOURCE_ARRAY( Node*, _idom_size );
2743   _dom_depth = NEW_RESOURCE_ARRAY( uint,  _idom_size );
2744   _dom_stk   = NULL; // Allocated on demand in recompute_dom_depth
2745   memset( _dom_depth, 0, _idom_size * sizeof(uint) );
2746 


< prev index next >