loopopts.cpp revision 1254
2362N/A * Copyright 1999-2010 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2362N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A#
include "incls/_precompiled.incl" 0N/A//============================================================================= 0N/A//------------------------------split_thru_phi--------------------------------- 0N/A// Split Node 'n' through merge point if there is enough win. 0N/A // ConvI2L may have type information on it which is unsafe to push up 0N/A // so disable this for now 0N/A x = C->
top();
// Dead path? Use a dead data op 0N/A x = n->
clone();
// Else clone up the data op 0N/A // Alter data node to use pre-phi inputs 0N/A // Check for a 'win' on some paths 0N/A // A TOP singleton indicates that there are no possible values incoming 0N/A // along a particular edge. In most cases, this is OK, and the Phi will 0N/A // be eliminated later in an Ideal call. However, we can't allow this to 0N/A // happen if the singleton occurs on loop entry, as the elimination of 0N/A // the PhiNode may cause the resulting node to migrate back to a previous 0N/A // Is_Loop() == false does not confirm the absence of a loop (e.g., an 0N/A // irreducible loop may not be indicated by an affirmative is_Loop()); 0N/A // therefore, the only top we can split thru a phi is on a backedge of 0N/A // We now call Identity to try to simplify the cloned node. // Note that some Identity methods call phase->type(this). // Make sure that the type array is big enough for // our new node, even though we may throw the node away. // (Note: This tweaking with igvn only works because x is a new node.) // If x is a TypeNode, capture any more-precise type permanently into Node // otherwise it will be not updated during igvn->transform since // igvn->type(x) is set to x->Value() already. // Else x is a new node we are keeping // We do not need register_new_node_with_optimizer // because set_type has already been called. // If we commoned up the cloned 'x' with another existing Node, // the existing Node picks up a new use. We need to make the // existing Node occur higher up so it dominates its uses. // The occasional new node // New late point must dominate new use // If changing loop bodies, see if we need to collect into new body //------------------------------dominated_by------------------------------------ // Replace the dominated test with an obvious true or false. Place it on the // IGVN worklist for later cleanup. Move control-dependent data Nodes on the // live path up to the dominating control. // prevdom is the dominating projection of the dominating test. // 'con' is set to true or false to kill the dominated test. // Hack the dominated test // If I dont have a reachable TRUE and FALSE path following the IfNode then // I can assume this path reaches an infinite loop. In this case it's not // important to optimize the data Nodes - either the whole compilation will // be tossed or this path (and all data Nodes) will go dead. // Make control-dependent data Nodes on the live path (path that will remain // once the dominated IF is removed) become control-dependent on the // dominating projection. //------------------------------has_local_phi_input---------------------------- // Return TRUE if 'n' has Phi inputs from its local block and no other // block-local inputs (all non-local-phi inputs come from earlier blocks) // See if some inputs come from a Phi in this block, or from before for( i =
1; i < n->
req(); i++ ) {
return NULL;
// No Phi inputs; nowhere to clone thru // Check for inputs created between 'n' and the Phi input. These // must split as well; they have already been given the chance // (courtesy of a post-order visit) and since they did not we must // recover the 'cost' of splitting them by being very profitable // when splitting 'n'. Since this is unlikely we simply give up. for( i =
1; i < n->
req(); i++ ) {
// We allow the special case of AddP's with no local inputs. // This allows us to split-up address expressions. // Move the AddP up to dominating point //------------------------------remix_address_expressions---------------------- // Rework addressing expressions to get the most loop-invariant stuff // moved out. We'd like to do all associative operators, but it's especially // important (common) to do address expressions. // See if 'n' mixes loop-varying and loop-invariant inputs and // itself is loop-varying. // Only interested in binary ops (and AddP) // Does one of my inputs spin in a tighter loop than self? return NULL;
// Leave well enough alone // Is at least one of my inputs loop-invariant? return NULL;
// No loop-invariant inputs // Replace expressions like ((V+I) << 2) with (V<<2 + I<<2). // Scale is loop invariant // Add must vary with loop (else shift would be loop-invariant) //assert( n_loop == add_loop, "" ); // Convert I-V into I+ (0-V); same for V-I // See if one add input is loop invariant // Swap to find the invariant part }
else // Else neither input is loop invariant return NULL;
// No invariant part of the add? // Yes! Reshape address expression! // Replace (I+V) with (V+I) // Replace ((I1 +p V) +p I2) with ((I1 +p I2) +p V), // but not if I2 is a constant. // Stuff new AddP in the loop preheader // Replace (I1 +p (I2 + V)) with ((I1 +p I2) +p V) // Stuff new AddP in the loop preheader //------------------------------conditional_move------------------------------- // Attempt to replace a Phi with a conditional move. We have some pretty // strict profitability requirements. All Phis at the merge point must // be converted, so we can remove the control flow. We need to limit the // number of c-moves to a small handful. All code that was in the side-arms // of the CFG diamond is now speculatively executed. This code has to be // "cheap enough". We are pretty much limited to CFG diamonds that merge // 1 or 2 items with a total of 1 or 2 ops executed speculatively. // Check for highly predictable branch. No point in CMOV'ing if // we are going to predict accurately all the time. // %%% This hides patterns produced by utility methods like Math.min. // Check for ops pinned in an arm of the diamond. // Can't remove the control flow in this case if( !
out->
is_Phi() )
continue;
// Ignore other control edges, etc cost++;
// Probably encodes as 2 CMOV's case T_INT:
// These all CMOV fine case T_OBJECT: {
// Base oops are OK, but not derived oops // Derived pointers are Bad (tm): what's the Base (for GC purposes) of a // CMOVE'd derived pointer? It's a CMOVE'd derived base. Thus // CMOVE'ing a derived pointer requires we also CMOVE the base. If we // have a Phi for the base here that we convert to a CMOVE all is well // and good. But if the base is dead, we'll not make a CMOVE. Later // the allocator will have to produce a base by creating a CMOVE of the // relevant bases. This puts the allocator in the business of // manufacturing expensive instructions, generally a bad plan. // Just Say No to Conditionally-Moved Derived Pointers. return NULL;
// In particular, can't do memory or I/O // Add in cost any speculative ops // Check for a chain of dependent ops; these will all become // speculative in a CMOV. return NULL;
// Too much speculative goo // See if the Phi is used by a Cmp or Narrow oop Decode/Encode. // This will likely Split-If, a higher-payoff operation. // It is expensive to generate flags from a float compare. // Avoid duplicated float compare. // Now replace all Phis with CMOV's // The useless CFG diamond will fold up later; see the optimization in //------------------------------split_if_with_blocks_pre----------------------- // Do the real work in a non-recursive function. Data nodes want to be // cloned in the pre-order so they can feed each other nicely. // Cloning these guys is unlikely to win // Do not clone-up CmpFXXX variations, as these are always // Attempt to use a conditional move instead of a phi/branch if( n->
is_Con() )
return n;
// No cloning for Con nodes if( !
n_ctrl )
return n;
// Dead node // Attempt to remix address expressions for loop invariants // Determine if the Node has inputs from some local Phi. // Returns the block to clone thru. // Do not clone the trip counter through on a CountedLoop // (messes up the canonical shape). // Check for having no control input; not pinned. Allow // Policy: when is it profitable. You must get more wins than // policy before it is considered profitable. Policy is usually 0, // so 1 win is considered profitable. Big merges will require big // cloning, so get a larger policy. // If the loop is a candidate for range check elimination, // delay splitting through it's phi until a later loop optimization // Use same limit as split_if_with_blocks_post if( C->
unique() >
35000 )
return n;
// Method too big // Split 'n' through the merge point if it is profitable // Found a Phi to split thru! // Replace 'n' with the new phi // Moved a load around the loop, 'en-registering' something. // Bail out if the region and its phis have too many users. // 4799512: Stop split_if_with_blocks from splitting a block with a ConvI2LNode // having a PhiNode input. This sidesteps the dangerous case where the split // ConvI2LNode may become TOP if the input Value() does not // overlap the ConvI2L range, leaving a node which may not dominate its // A better fix for this problem can be found in the BugTraq entry, but // expediency for Mantis demands this hack. // 6855164: If the merge point has a FastLockNode with a PhiNode input, we stop // split_if_with_blocks from splitting a block because we could not move around //------------------------------place_near_use--------------------------------- // Place some computation next to use but not inside inner loops. // For inner loop uses move it to the preheader area. //------------------------------split_if_with_blocks_post---------------------- // Do the real work in a non-recursive function. CFG hackery wants to be // in the post-order, so it can dirty the I-DOM info and not use the dirtied // Cloning Cmp through Phi's involves the split-if transform. // FastLock is not used by an If if( C->
unique() >
35000 )
return;
// Method too big // Do not do 'split-if' if irreducible loops are present. // Determine if the Node has inputs from some local Phi. // Returns the block to clone thru. if( n->
outcnt() !=
1 )
return;
// Multiple bool's from 1 compare? if(
bol->
outcnt() !=
1 )
return;
// Multiple branches from 1 compare? // Check some safety conditions if(
iff->
is_If() ) {
// Classic split-if? if(
iff->
in(0) !=
n_ctrl )
return;
// Compare must be in same blk as if }
else if (
iff->
is_CMove()) {
// Trying to split-up a CMOVE return;
// Inputs not yet split-up return;
// Loop-invar test gates loop-varying CMOVE return;
// some other kind of node, such as an Allocate // Do not do 'split-if' if some paths are dead. First do dead code // elimination and then see if its still profitable. // When is split-if profitable? Every 'win' on means some control flow // goes dead, so it's almost always a win. // If trying to do a 'Split-If' at the loop head, it is only // profitable if the cmp folds up on BOTH paths. Otherwise we // risk peeling a loop forever. // CNC - Disabled for now. Requires careful handling of loop // body selection for the cloned code. Also, make sure we check // for any input path not being in the same loop as n_ctrl. For // irreducible loops we cannot check for 'n_ctrl->is_Loop()' // because the alternative loop entry points won't be converted // Check for safety of the merge point. // Split compare 'n' through the merge point if it is profitable // Found a Phi to split thru! // Replace 'n' with the new phi // Now split the bool up thru the phi // Conditional-move? Must split up now // Check for an IF ready to split; one that has its // condition codes input coming from a Phi at the block start. // Check for an IF being dominated by another IF same test // Check for same test used more than once? // Search up IDOMs to see if this IF is dominated. // Now search up IDOMs till cutoff, looking for a dominating test // Replace the dominated test with an obvious true or false. // Place it on the IGVN worklist for later cleanup. // See if a shared loop-varying computation has no loop-varying uses. // Happens if something is only used for JVM state in uncommon trap exits, // like various versions of induction variable+offset. Clone the // computation per usage to allow it to sink out of the loop. if (
has_ctrl(n) && !n->
in(0)) {
// n not dead and has no control edge (can float about) if( !
has_ctrl(u) )
break;
// Found control user bool did_break = (i <
imax);
// Did we break out of the previous loop? // If n is a load, get and save the result from get_late_ctrl(), // to be later used in calculating the control for n's clones. // If n is a load, and the late control is the same as the current // control, then the cloning of n is a pointless exercise, because // GVN will ensure that we end up where we started. Node *u = n->
last_out(j);
// Clone private computation per use // Replace all uses of normal nodes. Replace Phi uses // individually, so the separate Nodes can sink down while( u->
in(k) != n ) k++;
// x goes next to Phi input path for(
uint k = 0; k < u->
req(); k++ ) {
// Find control for 'x' next to use but not inside inner loops. // For inner loop uses get the preheader area. // For loads, add a control edge to a CFG node outside of the loop // to force them to not combine and return back inside the loop // during GVN optimization (4641526). // Because we are setting the actual control input, factor in // the result from get_late_ctrl() so we respect any // anti-dependences. (6233005). // Don't allow the control input to be a CFG splitting node. // Such nodes should only have ProjNodes as outs, e.g. IfNode // should only have IfTrueNode and IfFalseNode (4985384). // Some institutional knowledge is needed here: 'x' is // yanked because if the optimizer runs GVN on it all the // cloned x's will common up and undo this optimization and // be forced back in the loop. This is annoying because it // makes +VerifyOpto report false-positives on progress. I // tried setting control edges on the x's to force them to // not combine, but the matching gets worried when it tries // to fold a StoreP and an AddP together (as part of an // address expression) and the AddP and StoreP have // Check for Opaque2's who's loop has disappeared - who's input is in the // same loop nest as their output. Remove 'em, they are no longer useful. //------------------------------split_if_with_blocks--------------------------- // Check for aggressive application of 'split-if' optimization, // using basic block level info. // Do pre-visit work for root // Now do pre-visit work for this use nstack.
push(n, i);
// Save parent and next use's index. n =
use;
// Process all children of current use. // All of n's children have been processed, complete post-processing. // Finished all nodes on stack. // Get saved parent node and next use's index. Visit the rest of uses. //============================================================================= // C L O N E A L O O P B O D Y //------------------------------clone_iff-------------------------------------- // Passed in a Phi merging (recursively) some nearly equivalent Bool/Cmps. // "Nearly" because all Nodes have been cloned from the original in the loop, // but the fall-in edges to the Cmp are different. Clone bool/Cmp pairs // through the Phi recursively, and return a Bool. // Convert this Phi into a Phi merging Bools for( i =
1; i <
phi->
req(); i++ ) {
// Make Phis to merge the Cmp's inputs. for( i =
1; i <
phi->
req(); i++ ) {
// See if these Phis have been made before. // Register with optimizer if(
hit1 ) {
// Hit, toss just made Phi if(
hit2 ) {
// Hit, toss just made Phi //------------------------------clone_bool------------------------------------- // Passed in a Phi merging (recursively) some nearly equivalent Bool/Cmps. // "Nearly" because all Nodes have been cloned from the original in the loop, // but the fall-in edges to the Cmp are different. Clone bool/Cmp pairs // through the Phi recursively, and return a Bool. // Convert this Phi into a Phi merging Bools for( i =
1; i <
phi->
req(); i++ ) {
// Make Phis to merge the Cmp's inputs. // See if these Phis have been made before. // Register with optimizer if(
hit1 ) {
// Hit, toss just made Phi if(
hit2 ) {
// Hit, toss just made Phi //------------------------------sink_use--------------------------------------- // If 'use' was in the loop-exit block, it now needs to be sunk // below the post-loop merge point. //------------------------------clone_loop------------------------------------- // C L O N E A L O O P B O D Y // This is the basic building block of the loop optimizations. It clones an // entire loop body. It makes an old_new loop body mapping; with this mapping // you can find the new-loop equivalent to an old-loop node. All new-loop // nodes are exactly equal to their old-loop counterparts, all edges are the // same. All exits from the old-loop now have a RegionNode that merges the // equivalent new-loop path. This is true even for the normal "loop-exit" // condition. All uses of loop-invariant old-loop values now come from (one // or more) Phis that merge their new-loop equivalents. // This operation leaves the graph in an illegal state: there are two valid // control edges coming from the loop pre-header to both loop bodies. I'll // definitely have to hack the graph after running this transform. // From this building block I will further edit edges to perform loop peeling // or loop unrolling or iteration splitting (Range-Check-Elimination), etc. // Parameter side_by_size_idom: // When side_by_size_idom is NULL, the dominator tree is constructed for // the clone loop to dominate the original. Used in construction of // pre-main-post loop sequence. // When nonnull, the clone and original are side-by-side, both are // dominated by the side_by_side_idom node. Used in construction of // Step 1: Clone the loop body. Make the old->new mapping. // Step 2: Fix the edges in the new body. If the old input is outside the // loop use it. If the old input is INside the loop, use the corresponding // Fix CFG/Loop controlling the new node // Correct edges to the new node // Step 3: Now fix control uses. Loop varying control uses have already // been fixed up (as part of all input edges in Step 2). Loop invariant // control uses must be either an IfFalse or an IfTrue. Make a merge // point to merge the old and new IfFalse/IfTrue nodes; make the use // Copy uses to a worklist, so I can munge the def-use info // Both OLD and USE are CFG nodes here. // Clone the loop exit control projection // We need a Region to merge the exit from the peeled body and the // exit from the old loop body. // Map the old use to the new merge point // The original user of 'use' uses 'r' instead. l -=
uses_found;
// we deleted 1 or more copies of this edge }
// End of if a loop-exit test // Step 4: If loop-invariant use is not control, it must be dominated by a // loop exit IfFalse/IfTrue. Find "proper" loop exit. Make a Region // there if needed. Make a Phi there merging old and new used values. // Copy uses to a worklist, so I can munge the def-use info // Check for data-use outside of loop - at least one of OLD or USE // must not be a CFG node. // If the Data use is an IF, that means we have an IF outside of the // loop that is switching on a condition that is set inside of the // loop. Happens if people set a loop-exit flag; then test the flag // in the loop to break the loop, then test is again outside of the // loop to determine which way the loop exited. // Since this code is highly unlikely, we lazily build the worklist // of such Nodes to go split. if(
use->
is_Phi() )
// Phi use is in prior block // If the use occurs after merging several exits from the loop, then // old value must have dominated all those exits. Since the same old // value was used on all those exits we did not need a Phi at this // merge point. NOW we do need a Phi here. Each loop exit value // is now merged with the peeled body exit; each exit gets its own // private Phi and those Phis need to be merged here. if(
idx == 0 ) {
// Updating control edge? phi =
prev;
// Just use existing control }
else {
// Else need a new Phi // Now recursively fix up the new uses of old! // Get new RegionNode merging old and new loop exits if(
idx == 0 ) {
// Updating control edge? phi =
prev;
// Just use existing control }
else {
// Else need a new Phi // Make a new Phi merging data values properly // If inserting a new Phi, check for prior hits // Remove the new phi from the graph and use the hit phi =
hit;
// Use existing phi // Make 'use' use the Phi instead of the old loop body exit value // Not needed for correctness, but prevents a weak assert // in AddPNode from tripping (when we end up with different // base & derived Phis that will become the same after if(
hit )
// Go ahead and re-hash for hits. // If 'use' was in the loop-exit block, it now needs to be sunk // below the post-loop merge point. // the loop uses a condition set in the loop. The original IF probably // takes control from one or more OLD Regions (which in turn get from NEW // Regions). In any case, there will be a set of Phis for each merge point // from the IF up to where the original BOOL def exists the loop. //---------------------- stride_of_possible_iv ------------------------------------- // Looks for an iff/bool/comp with one operand of the compare // being a cycle involving an add and a phi, // with an optional truncation (left-shift followed by a right-shift) // of the add. Returns zero if not an iv. // Must have an invariant operand // (If (Bool (CmpX phi:(Phi ...(Optional-trunc(AddI phi add2))) ))) // (If (Bool (CmpX addtrunc:(Optional-trunc((AddI (Phi ...addtrunc...) add2)) ))) //---------------------- stay_in_loop ------------------------------------- // Return the (unique) control output node that's in the loop (if it exists.) //------------------------------ register_node ------------------------------------- // Utility to register node "n" with PhaseIdealLoop //------------------------------ proj_clone ------------------------------------- // Utility to create an if-projection //------------------------------ short_circuit_if ------------------------------------- // Force the iff control output to be the live_proj //------------------------------ insert_if_before_proj ------------------------------------- // Insert a new if before an if projection (* - new node) // * new_if(relop(cmp[IU](left,right))) //------------------------------ insert_region_before_proj ------------------------------------- // Insert a region before an if projection (* - new node) //------------------------------ insert_cmpi_loop_exit ------------------------------------- // Clone a signed compare loop exit from an unsigned compare and // insert it before the unsigned cmp on the stay-in-loop path. // All new nodes inserted in the dominator tree between the original // if and it's projections. The original if test is replaced with // a constant to force the stay-in-loop path. // This is done to make sure that the original if and it's projections // still dominate the same set of control nodes, that the ctrl() relation // from data nodes to them is preserved, and that their loop nesting is // if(i <u limit) unsigned compare loop exit // exit-proj stay-in-loop-proj // if(stay-in-loop-const) original if // / if(i < limit) new signed test // / / if(i <u limit) new cloned unsigned test // exit-proj stay-in-loop-proj // Create a new region on the exit path // Clone the if-cmpu-true-false using a signed compare // Clone the if-cmpu-true-false // Force original if to stay in loop. //------------------------------ remove_cmpi_loop_exit ------------------------------------- // Remove a previously inserted signed compare loop exit. //------------------------------ scheduled_nodelist ------------------------------------- // Create a post order schedule of nodes that are in the // "member" set. The list is returned in "sched". // The first node in "sched" is the loop head, followed by // nodes which have no inputs in the "member" set, and then // followed by the nodes that have an immediate input dependence // Initially push all with no inputs from within member set // traverse out's that are in the member set //------------------------------ has_use_in_set ------------------------------------- // Has a use in the vector set //------------------------------ has_use_internal_to_set ------------------------------------- // Has use internal to the vector set (ie. not in a phi at the loop head) //------------------------------ clone_for_use_outside_loop ------------------------------------- // clone "n" for uses that are outside of loop for (j = 0; j <
use->
req(); j++) {
if (
use->
in(j) == n)
break;
// clone "n" and insert it between the inputs of "n" and the use outside the loop // Use in a phi is considered a use in the associated predecessor block //------------------------------ clone_for_special_use_inside_loop ------------------------------------- // clone "n" for special uses that are in the not_peeled region. // If these def-uses occur in separate blocks, the code generator // marks the method as not compilable. For example, if a "BoolNode" // is in a different basic block than the "IfNode" that uses it, then // the compilation is aborted in the code generator. // clone "n" and insert it between inputs of "n" and the use //------------------------------ insert_phi_for_loop ------------------------------------- // Insert phi(lp_entry_val, back_edge_val) at use->in(idx) for loop lp if phi does not already exist // Use existing phi if it already exists // Remove the new phi from the graph and use the hit //------------------------------ is_valid_loop_partition ------------------------------------- // Validate the loop partition sets: peel and not_peel // Check that peel_list entries are in the peel set // Check at loop members are in one of peel set or not_peel set // Check that peel set elements are in peel_list // Must be in peel_list also //------------------------------ is_valid_clone_loop_exit_use ------------------------------------- // Ensure a use outside of loop is of the right form //------------------------------ is_valid_clone_loop_form ------------------------------------- // Ensure that all uses outside of loop are of the right form // use is not in the loop, check for correct structure //------------------------------ partial_peel ------------------------------------- // Partially peel (aka loop rotation) the top portion of a loop (called // the peel section below) by cloning it and placing one copy just before // the new loop head and the other copy at the bottom of the new loop. // before after where it came from // stmt2 if condA goto exitA clone // if condA goto exitA new_loop: new // if !condB goto loop if condB goto exitB clone // stmt4 if !condA goto new_loop orig // Step 1: find the cut point: an exit test on probable // Step 2: schedule (with cloning) operations in the peel // section that can be executed after the cut into // the section that is not peeled. This may need // to clone operations into exit blocks. For // instance, a reference to A[i] in the not-peel // section and a reference to B[i] in an exit block // may cause a left-shift of i by 2 to be placed // in the peel block. This step will clone the left // shift into the exit block and sink the left shift // from the peel to the not-peel section. // Step 3: clone the loop, retarget the control, and insert // phis for values that are live across the new loop // head. This is very dependent on the graph structure // from clone_loop. It creates region nodes for // exit control and associated phi nodes for values // flow out of the loop through that exit. The region // node is dominated by the clone's control projection. // So the clone's peel section is placed before the // new loop head, and the clone's not-peel section is // forms the top part of the new loop. The original // peel section forms the tail of the new loop. // Step 4: update the dominator tree and recompute the // false true ^ <-- last_peel // / stmt3 | <-- first_not_peel // ^ true false false true ^ <-- last_peel // | cut==|== \ \ / ===|==cut | // | stmt3 \ \ / stmt3 | <-- first_not_peel // | true false false true | // TOP->region region----+ // true false false true | <-- last_peel // +->newloop \ \ / === ==cut | | // | | dom | | stmt3 | | <-- first_not_peel // | true false false true | | // | +------------>-----------------+ | // +-----------------<---------------------+ // Check for complex exit control // Step 1: find cut point // Walk up dominators to loop head looking for first loop exit // which is executed on every path thru loop. if (
ctrl->
is_top())
return false;
// Dead test on live IF. // If loop-varying exit-test, check for induction variable // Prefer signed compare over unsigned compare. return false;
// No peel point found return false;
// No peel point found // Set of cfg nodes to peel are those that are executable from // the head through last_peel. // Set of non-cfg nodes to peel are those that are control // dependent on the cfg nodes. // Step 2: move operations from the peeled section down into the // Get a post order schedule of nodes in the peel region // Result in right-most operand. // For future check for too many new phis // Evacuate nodes in peel region into the not_peeled region if possible // If not used internal to the peeled region, // move "n" from peeled to not_peeled region. // if not pinned and not a load (which maybe anti-dependent on a store) // and not a CMove (Matcher expects only bool->cmove). peel >>= n->
_idx;
// delete n from peel set. tty->
print_cr(
"sink to not_peeled region: %d newbb: %d",
// Otherwise check for special def-use cases that span tty->
print_cr(
"\nToo many new phis: %d old %d new cmpi: %c",
// Inhibit more partial peeling on this loop // Step 3: clone loop, retarget control, and insert new phis // Create new loop head for new phis and to hang // the nodes being moved (sinked) from the peel region. // Add phi if "def" node is in peel set and "use" is not // "def" is in peel set, "use" is not in peel set // or "use" is in the entry boundary (a phi) of the peel set // use is not in the loop, check if the live range includes the cut // Step 3b: retarget control // Redirect control to the new loop head if a cloned node in // the not_peeled region has control that points into the peeled region. // This necessary because the cloned peeled region will be outside // new_head_clone: | <--+ // cloned-not_peeled in(0) in(0) // Backedge of the surviving new_head (the clone) is original last_peel // Cut first node in original not_peel set // Copy head_clone back-branch info to original head // and remove original head's loop entry and // clone head's back-branch // Similarly modify the phis // Step 4: update dominator tree and dominator depth // Inhibit more partial peeling on this loop //------------------------------reorg_offsets---------------------------------- // Reorganize offset computations to lower register pressure. Mostly // prevent loop-fallout uses of the pre-incremented trip counter (which are // then alive with the post-incremented trip counter forcing an extra if( !
cle )
return;
// The occasional dead loop // Find loop exit control // Check for the special case of folks using the pre-incremented // trip-counter on the fall-out path (forces the pre-incremented // and post-incremented trip counter to be live at the same time). // Fix this by adjusting to use the post-increment trip counter. if( !
phi )
return;
// Dead infinite loop // Shape messed up, probably by iteration_split_impl // Look for loop-invariant use // Check that use is live out the bottom. Assuming the trip-counter // update is right at the bottom, uses of of the loop middle are ok. // protect against stride not being a constant // Hit! Refactor use to use the post-incremented tripcounter. // Compute a post-increment tripcounter. // Since DU info changed, rerun loop