src/share/vm/opto/loopTransform.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8148754 Sdiff src/share/vm/opto

src/share/vm/opto/loopTransform.cpp

Print this page




1436     Node_List rpo_list;
1437     VectorSet visited(arena);
1438     visited.set(loop_head->_idx);
1439     rpo( loop_head, stack, visited, rpo_list );
1440     dump(loop, rpo_list.size(), rpo_list );
1441   }
1442 #endif
1443 
1444   // Remember loop node count before unrolling to detect
1445   // if rounds of unroll,optimize are making progress
1446   loop_head->set_node_count_before_unroll(loop->_body.size());
1447 
1448   Node *ctrl  = loop_head->in(LoopNode::EntryControl);
1449   Node *limit = loop_head->limit();
1450   Node *init  = loop_head->init_trip();
1451   Node *stride = loop_head->stride();
1452 
1453   Node *opaq = NULL;
1454   if (adjust_min_trip) {       // If not maximally unrolling, need adjustment
1455     // Search for zero-trip guard.
1456     assert( loop_head->is_main_loop(), "" );
1457     assert( ctrl->Opcode() == Op_IfTrue || ctrl->Opcode() == Op_IfFalse, "" );
1458     Node *iff = ctrl->in(0);
1459     assert( iff->Opcode() == Op_If, "" );
1460     Node *bol = iff->in(1);
1461     assert( bol->Opcode() == Op_Bool, "" );
1462     Node *cmp = bol->in(1);
1463     assert( cmp->Opcode() == Op_CmpI, "" );
1464     opaq = cmp->in(2);
1465     // Occasionally it's possible for a zero-trip guard Opaque1 node to be
1466     // optimized away and then another round of loop opts attempted.
1467     // We can not optimize this particular loop in that case.
1468     if (opaq->Opcode() != Op_Opaque1)
1469       return; // Cannot find zero-trip guard!  Bail out!
1470     // Zero-trip test uses an 'opaque' node which is not shared.
1471     assert(opaq->outcnt() == 1 && opaq->in(1) == limit, "");
1472   }
1473 
1474   C->set_major_progress();
1475 
1476   Node* new_limit = NULL;
1477   if (UnrollLimitCheck) {
1478     int stride_con = stride->get_int();
1479     int stride_p = (stride_con > 0) ? stride_con : -stride_con;
1480     uint old_trip_count = loop_head->trip_count();
1481     // Verify that unroll policy result is still valid.
1482     assert(old_trip_count > 1 &&
1483            (!adjust_min_trip || stride_p <= (1<<3)*loop_head->unrolled_count()), "sanity");
1484 
1485     // Adjust loop limit to keep valid iterations number after unroll.
1486     // Use (limit - stride) instead of (((limit - init)/stride) & (-2))*stride
1487     // which may overflow.
1488     if (!adjust_min_trip) {
1489       assert(old_trip_count > 1 && (old_trip_count & 1) == 0,


2092       return true;
2093     }
2094   }
2095   return false;
2096 }
2097 
2098 //------------------------------do_range_check---------------------------------
2099 // Eliminate range-checks and other trip-counter vs loop-invariant tests.
2100 void PhaseIdealLoop::do_range_check( IdealLoopTree *loop, Node_List &old_new ) {
2101 #ifndef PRODUCT
2102   if (PrintOpto && VerifyLoopOptimizations) {
2103     tty->print("Range Check Elimination ");
2104     loop->dump_head();
2105   } else if (TraceLoopOpts) {
2106     tty->print("RangeCheck   ");
2107     loop->dump_head();
2108   }
2109 #endif
2110   assert(RangeCheckElimination, "");
2111   CountedLoopNode *cl = loop->_head->as_CountedLoop();
2112   assert(cl->is_main_loop(), "");
2113 
2114   // protect against stride not being a constant
2115   if (!cl->stride_is_con())
2116     return;
2117 
2118   // Find the trip counter; we are iteration splitting based on it
2119   Node *trip_counter = cl->phi();
2120   // Find the main loop limit; we will trim it's iterations
2121   // to not ever trip end tests
2122   Node *main_limit = cl->limit();
2123 







2124   // Need to find the main-loop zero-trip guard
2125   Node *ctrl  = cl->in(LoopNode::EntryControl);
2126   assert(ctrl->Opcode() == Op_IfTrue || ctrl->Opcode() == Op_IfFalse, "");
2127   Node *iffm = ctrl->in(0);
2128   assert(iffm->Opcode() == Op_If, "");
2129   Node *bolzm = iffm->in(1);
2130   assert(bolzm->Opcode() == Op_Bool, "");
2131   Node *cmpzm = bolzm->in(1);
2132   assert(cmpzm->is_Cmp(), "");
2133   Node *opqzm = cmpzm->in(2);
2134   // Can not optimize a loop if zero-trip Opaque1 node is optimized
2135   // away and then another round of loop opts attempted.
2136   if (opqzm->Opcode() != Op_Opaque1)
2137     return;
2138   assert(opqzm->in(1) == main_limit, "do not understand situation");
2139 
2140   // Find the pre-loop limit; we will expand its iterations to
2141   // not ever trip low tests.
2142   Node *p_f = iffm->in(0);
2143   // pre loop may have been optimized out
2144   if (p_f->Opcode() != Op_IfFalse) {
2145     return;
2146   }
2147   CountedLoopEndNode *pre_end = p_f->in(0)->as_CountedLoopEnd();
2148   assert(pre_end->loopnode()->is_pre_loop(), "");
2149   Node *pre_opaq1 = pre_end->limit();
2150   // Occasionally it's possible for a pre-loop Opaque1 node to be
2151   // optimized away and then another round of loop opts attempted.
2152   // We can not optimize this particular loop in that case.
2153   if (pre_opaq1->Opcode() != Op_Opaque1)
2154     return;
2155   Opaque1Node *pre_opaq = (Opaque1Node*)pre_opaq1;
2156   Node *pre_limit = pre_opaq->in(1);
2157 




1436     Node_List rpo_list;
1437     VectorSet visited(arena);
1438     visited.set(loop_head->_idx);
1439     rpo( loop_head, stack, visited, rpo_list );
1440     dump(loop, rpo_list.size(), rpo_list );
1441   }
1442 #endif
1443 
1444   // Remember loop node count before unrolling to detect
1445   // if rounds of unroll,optimize are making progress
1446   loop_head->set_node_count_before_unroll(loop->_body.size());
1447 
1448   Node *ctrl  = loop_head->in(LoopNode::EntryControl);
1449   Node *limit = loop_head->limit();
1450   Node *init  = loop_head->init_trip();
1451   Node *stride = loop_head->stride();
1452 
1453   Node *opaq = NULL;
1454   if (adjust_min_trip) {       // If not maximally unrolling, need adjustment
1455     // Search for zero-trip guard.
1456 
1457     // Check the shape of the graph at the loop entry. If an inappropriate
1458     // graph shape is encountered, the compiler bails out loop unrolling;
1459     // compilation of the method will still succeed.
1460     if (!is_canonical_main_loop_entry(loop_head)) {
1461       return;
1462     }
1463     opaq = ctrl->in(0)->in(1)->in(1)->in(2);






1464     // Zero-trip test uses an 'opaque' node which is not shared.
1465     assert(opaq->outcnt() == 1 && opaq->in(1) == limit, "");
1466   }
1467 
1468   C->set_major_progress();
1469 
1470   Node* new_limit = NULL;
1471   if (UnrollLimitCheck) {
1472     int stride_con = stride->get_int();
1473     int stride_p = (stride_con > 0) ? stride_con : -stride_con;
1474     uint old_trip_count = loop_head->trip_count();
1475     // Verify that unroll policy result is still valid.
1476     assert(old_trip_count > 1 &&
1477            (!adjust_min_trip || stride_p <= (1<<3)*loop_head->unrolled_count()), "sanity");
1478 
1479     // Adjust loop limit to keep valid iterations number after unroll.
1480     // Use (limit - stride) instead of (((limit - init)/stride) & (-2))*stride
1481     // which may overflow.
1482     if (!adjust_min_trip) {
1483       assert(old_trip_count > 1 && (old_trip_count & 1) == 0,


2086       return true;
2087     }
2088   }
2089   return false;
2090 }
2091 
2092 //------------------------------do_range_check---------------------------------
2093 // Eliminate range-checks and other trip-counter vs loop-invariant tests.
2094 void PhaseIdealLoop::do_range_check( IdealLoopTree *loop, Node_List &old_new ) {
2095 #ifndef PRODUCT
2096   if (PrintOpto && VerifyLoopOptimizations) {
2097     tty->print("Range Check Elimination ");
2098     loop->dump_head();
2099   } else if (TraceLoopOpts) {
2100     tty->print("RangeCheck   ");
2101     loop->dump_head();
2102   }
2103 #endif
2104   assert(RangeCheckElimination, "");
2105   CountedLoopNode *cl = loop->_head->as_CountedLoop();

2106 
2107   // protect against stride not being a constant
2108   if (!cl->stride_is_con())
2109     return;
2110 
2111   // Find the trip counter; we are iteration splitting based on it
2112   Node *trip_counter = cl->phi();
2113   // Find the main loop limit; we will trim it's iterations
2114   // to not ever trip end tests
2115   Node *main_limit = cl->limit();
2116 
2117   // Check graph shape. Cannot optimize a loop if zero-trip
2118   // Opaque1 node is optimized away and then another round
2119   // of loop opts attempted.
2120   if (!is_canonical_main_loop_entry(cl)) {
2121     return;
2122   }
2123 
2124   // Need to find the main-loop zero-trip guard
2125   Node *ctrl  = cl->in(LoopNode::EntryControl);

2126   Node *iffm = ctrl->in(0);
2127   Node *opqzm = iffm->in(1)->in(1)->in(2);









2128   assert(opqzm->in(1) == main_limit, "do not understand situation");
2129 
2130   // Find the pre-loop limit; we will expand its iterations to
2131   // not ever trip low tests.
2132   Node *p_f = iffm->in(0);
2133   // pre loop may have been optimized out
2134   if (p_f->Opcode() != Op_IfFalse) {
2135     return;
2136   }
2137   CountedLoopEndNode *pre_end = p_f->in(0)->as_CountedLoopEnd();
2138   assert(pre_end->loopnode()->is_pre_loop(), "");
2139   Node *pre_opaq1 = pre_end->limit();
2140   // Occasionally it's possible for a pre-loop Opaque1 node to be
2141   // optimized away and then another round of loop opts attempted.
2142   // We can not optimize this particular loop in that case.
2143   if (pre_opaq1->Opcode() != Op_Opaque1)
2144     return;
2145   Opaque1Node *pre_opaq = (Opaque1Node*)pre_opaq1;
2146   Node *pre_limit = pre_opaq->in(1);
2147 


src/share/vm/opto/loopTransform.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File