204 void IdealLoopTree::reassociate_invariants(PhaseIdealLoop *phase) {
205 for (int i = _body.size() - 1; i >= 0; i--) {
206 Node *n = _body.at(i);
207 for (int j = 0; j < 5; j++) {
208 Node* nn = reassociate_add_sub(n, phase);
209 if (nn == NULL) break;
210 n = nn; // again
211 };
212 }
213 }
214
215 //------------------------------policy_peeling---------------------------------
216 // Return TRUE or FALSE if the loop should be peeled or not. Peel if we can
217 // make some loop-invariant test (usually a null-check) happen before the loop.
218 bool IdealLoopTree::policy_peeling( PhaseIdealLoop *phase ) const {
219 Node *test = ((IdealLoopTree*)this)->tail();
220 int body_size = ((IdealLoopTree*)this)->_body.size();
221 int uniq = phase->C->unique();
222 // Peeling does loop cloning which can result in O(N^2) node construction
223 if( body_size > 255 /* Prevent overflow for large body_size */
224 || (body_size * body_size + uniq > MaxNodeLimit) ) {
225 return false; // too large to safely clone
226 }
227 while( test != _head ) { // Scan till run off top of loop
228 if( test->is_If() ) { // Test?
229 Node *ctrl = phase->get_ctrl(test->in(1));
230 if (ctrl->is_top())
231 return false; // Found dead test on live IF? No peeling!
232 // Standard IF only has one input value to check for loop invariance
233 assert( test->Opcode() == Op_If || test->Opcode() == Op_CountedLoopEnd, "Check this code when new subtype is added");
234 // Condition is not a member of this loop?
235 if( !is_member(phase->get_loop(ctrl)) &&
236 is_loop_exit(test) )
237 return true; // Found reason to peel!
238 }
239 // Walk up dominators to loop _head looking for test which is
240 // executed on every path thru loop.
241 test = phase->idom(test);
242 }
243 return false;
244 }
399 if (init >= limit || stride > span) {
400 // return a false (no maximally unroll) and the regular unroll/peel
401 // route will make a small mess which CCP will fold away.
402 return false;
403 }
404 uint trip_count = span/stride; // trip_count can be greater than 2 Gig.
405 assert( (int)trip_count*stride == span, "must divide evenly" );
406
407 // Real policy: if we maximally unroll, does it get too big?
408 // Allow the unrolled mess to get larger than standard loop
409 // size. After all, it will no longer be a loop.
410 uint body_size = _body.size();
411 uint unroll_limit = (uint)LoopUnrollLimit * 4;
412 assert( (intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits");
413 cl->set_trip_count(trip_count);
414 if( trip_count <= unroll_limit && body_size <= unroll_limit ) {
415 uint new_body_size = body_size * trip_count;
416 if (new_body_size <= unroll_limit &&
417 body_size == new_body_size / trip_count &&
418 // Unrolling can result in a large amount of node construction
419 new_body_size < MaxNodeLimit - phase->C->unique()) {
420 return true; // maximally unroll
421 }
422 }
423
424 return false; // Do not maximally unroll
425 }
426
427
428 //------------------------------policy_unroll----------------------------------
429 // Return TRUE or FALSE if the loop should be unrolled or not. Unroll if
430 // the loop is a CountedLoop and the body is small enough.
431 bool IdealLoopTree::policy_unroll( PhaseIdealLoop *phase ) const {
432
433 CountedLoopNode *cl = _head->as_CountedLoop();
434 assert( cl->is_normal_loop() || cl->is_main_loop(), "" );
435
436 // protect against stride not being a constant
437 if( !cl->stride_is_con() ) return false;
438
439 // protect against over-unrolling
|
204 void IdealLoopTree::reassociate_invariants(PhaseIdealLoop *phase) {
205 for (int i = _body.size() - 1; i >= 0; i--) {
206 Node *n = _body.at(i);
207 for (int j = 0; j < 5; j++) {
208 Node* nn = reassociate_add_sub(n, phase);
209 if (nn == NULL) break;
210 n = nn; // again
211 };
212 }
213 }
214
215 //------------------------------policy_peeling---------------------------------
216 // Return TRUE or FALSE if the loop should be peeled or not. Peel if we can
217 // make some loop-invariant test (usually a null-check) happen before the loop.
218 bool IdealLoopTree::policy_peeling( PhaseIdealLoop *phase ) const {
219 Node *test = ((IdealLoopTree*)this)->tail();
220 int body_size = ((IdealLoopTree*)this)->_body.size();
221 int uniq = phase->C->unique();
222 // Peeling does loop cloning which can result in O(N^2) node construction
223 if( body_size > 255 /* Prevent overflow for large body_size */
224 || (body_size * body_size + uniq > phase->C->nodes_limit()) ) {
225 return false; // too large to safely clone
226 }
227 while( test != _head ) { // Scan till run off top of loop
228 if( test->is_If() ) { // Test?
229 Node *ctrl = phase->get_ctrl(test->in(1));
230 if (ctrl->is_top())
231 return false; // Found dead test on live IF? No peeling!
232 // Standard IF only has one input value to check for loop invariance
233 assert( test->Opcode() == Op_If || test->Opcode() == Op_CountedLoopEnd, "Check this code when new subtype is added");
234 // Condition is not a member of this loop?
235 if( !is_member(phase->get_loop(ctrl)) &&
236 is_loop_exit(test) )
237 return true; // Found reason to peel!
238 }
239 // Walk up dominators to loop _head looking for test which is
240 // executed on every path thru loop.
241 test = phase->idom(test);
242 }
243 return false;
244 }
399 if (init >= limit || stride > span) {
400 // return a false (no maximally unroll) and the regular unroll/peel
401 // route will make a small mess which CCP will fold away.
402 return false;
403 }
404 uint trip_count = span/stride; // trip_count can be greater than 2 Gig.
405 assert( (int)trip_count*stride == span, "must divide evenly" );
406
407 // Real policy: if we maximally unroll, does it get too big?
408 // Allow the unrolled mess to get larger than standard loop
409 // size. After all, it will no longer be a loop.
410 uint body_size = _body.size();
411 uint unroll_limit = (uint)LoopUnrollLimit * 4;
412 assert( (intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits");
413 cl->set_trip_count(trip_count);
414 if( trip_count <= unroll_limit && body_size <= unroll_limit ) {
415 uint new_body_size = body_size * trip_count;
416 if (new_body_size <= unroll_limit &&
417 body_size == new_body_size / trip_count &&
418 // Unrolling can result in a large amount of node construction
419 new_body_size < phase->C->nodes_limit() - phase->C->unique()) {
420 return true; // maximally unroll
421 }
422 }
423
424 return false; // Do not maximally unroll
425 }
426
427
428 //------------------------------policy_unroll----------------------------------
429 // Return TRUE or FALSE if the loop should be unrolled or not. Unroll if
430 // the loop is a CountedLoop and the body is small enough.
431 bool IdealLoopTree::policy_unroll( PhaseIdealLoop *phase ) const {
432
433 CountedLoopNode *cl = _head->as_CountedLoop();
434 assert( cl->is_normal_loop() || cl->is_main_loop(), "" );
435
436 // protect against stride not being a constant
437 if( !cl->stride_is_con() ) return false;
438
439 // protect against over-unrolling
|