Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/loopTransform.cpp @ 2412:f9424955eb18
7029152: Ideal nodes for String intrinsics miss memory edge optimization
Summary: In Ideal() method of String intrinsics nodes look for TypeAryPtr::CHARS memory slice if memory is MergeMem. Do not unroll a loop with String intrinsics code.
Reviewed-by: never
author | kvn |
---|---|
date | Wed, 30 Mar 2011 12:08:49 -0700 |
parents | 1927db75dd85 |
children | cb162b348743 |
comparison
equal
deleted
inserted
replaced
2411:63997f575155 | 2412:f9424955eb18 |
---|---|
394 | 394 |
395 //------------------------------policy_maximally_unroll------------------------ | 395 //------------------------------policy_maximally_unroll------------------------ |
396 // Return exact loop trip count, or 0 if not maximally unrolling | 396 // Return exact loop trip count, or 0 if not maximally unrolling |
397 bool IdealLoopTree::policy_maximally_unroll( PhaseIdealLoop *phase ) const { | 397 bool IdealLoopTree::policy_maximally_unroll( PhaseIdealLoop *phase ) const { |
398 CountedLoopNode *cl = _head->as_CountedLoop(); | 398 CountedLoopNode *cl = _head->as_CountedLoop(); |
399 assert( cl->is_normal_loop(), "" ); | 399 assert(cl->is_normal_loop(), ""); |
400 | 400 |
401 Node *init_n = cl->init_trip(); | 401 Node *init_n = cl->init_trip(); |
402 Node *limit_n = cl->limit(); | 402 Node *limit_n = cl->limit(); |
403 | 403 |
404 // Non-constant bounds | 404 // Non-constant bounds |
405 if( init_n == NULL || !init_n->is_Con() || | 405 if (init_n == NULL || !init_n->is_Con() || |
406 limit_n == NULL || !limit_n->is_Con() || | 406 limit_n == NULL || !limit_n->is_Con() || |
407 // protect against stride not being a constant | 407 // protect against stride not being a constant |
408 !cl->stride_is_con() ) { | 408 !cl->stride_is_con()) { |
409 return false; | 409 return false; |
410 } | 410 } |
411 int init = init_n->get_int(); | 411 int init = init_n->get_int(); |
412 int limit = limit_n->get_int(); | 412 int limit = limit_n->get_int(); |
413 int span = limit - init; | 413 int span = limit - init; |
426 // size. After all, it will no longer be a loop. | 426 // size. After all, it will no longer be a loop. |
427 uint body_size = _body.size(); | 427 uint body_size = _body.size(); |
428 uint unroll_limit = (uint)LoopUnrollLimit * 4; | 428 uint unroll_limit = (uint)LoopUnrollLimit * 4; |
429 assert( (intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits"); | 429 assert( (intx)unroll_limit == LoopUnrollLimit * 4, "LoopUnrollLimit must fit in 32bits"); |
430 cl->set_trip_count(trip_count); | 430 cl->set_trip_count(trip_count); |
431 if( trip_count <= unroll_limit && body_size <= unroll_limit ) { | 431 if (trip_count > unroll_limit || body_size > unroll_limit) { |
432 return false; | |
433 } | |
434 | |
435 // Do not unroll a loop with String intrinsics code. | |
436 // String intrinsics are large and have loops. | |
437 for (uint k = 0; k < _body.size(); k++) { | |
438 Node* n = _body.at(k); | |
439 switch (n->Opcode()) { | |
440 case Op_StrComp: | |
441 case Op_StrEquals: | |
442 case Op_StrIndexOf: | |
443 case Op_AryEq: { | |
444 return false; | |
445 } | |
446 } // switch | |
447 } | |
448 | |
449 if (body_size <= unroll_limit) { | |
432 uint new_body_size = body_size * trip_count; | 450 uint new_body_size = body_size * trip_count; |
433 if (new_body_size <= unroll_limit && | 451 if (new_body_size <= unroll_limit && |
434 body_size == new_body_size / trip_count && | 452 body_size == new_body_size / trip_count && |
435 // Unrolling can result in a large amount of node construction | 453 // Unrolling can result in a large amount of node construction |
436 new_body_size < MaxNodeLimit - phase->C->unique()) { | 454 new_body_size < MaxNodeLimit - phase->C->unique()) { |
446 // Return TRUE or FALSE if the loop should be unrolled or not. Unroll if | 464 // Return TRUE or FALSE if the loop should be unrolled or not. Unroll if |
447 // the loop is a CountedLoop and the body is small enough. | 465 // the loop is a CountedLoop and the body is small enough. |
448 bool IdealLoopTree::policy_unroll( PhaseIdealLoop *phase ) const { | 466 bool IdealLoopTree::policy_unroll( PhaseIdealLoop *phase ) const { |
449 | 467 |
450 CountedLoopNode *cl = _head->as_CountedLoop(); | 468 CountedLoopNode *cl = _head->as_CountedLoop(); |
451 assert( cl->is_normal_loop() || cl->is_main_loop(), "" ); | 469 assert(cl->is_normal_loop() || cl->is_main_loop(), ""); |
452 | 470 |
453 // protect against stride not being a constant | 471 // protect against stride not being a constant |
454 if( !cl->stride_is_con() ) return false; | 472 if (!cl->stride_is_con()) return false; |
455 | 473 |
456 // protect against over-unrolling | 474 // protect against over-unrolling |
457 if( cl->trip_count() <= 1 ) return false; | 475 if (cl->trip_count() <= 1) return false; |
458 | 476 |
459 int future_unroll_ct = cl->unrolled_count() * 2; | 477 int future_unroll_ct = cl->unrolled_count() * 2; |
460 | 478 |
461 // Don't unroll if the next round of unrolling would push us | 479 // Don't unroll if the next round of unrolling would push us |
462 // over the expected trip count of the loop. One is subtracted | 480 // over the expected trip count of the loop. One is subtracted |
483 Node *init_n = cl->init_trip(); | 501 Node *init_n = cl->init_trip(); |
484 Node *limit_n = cl->limit(); | 502 Node *limit_n = cl->limit(); |
485 // Non-constant bounds. | 503 // Non-constant bounds. |
486 // Protect against over-unrolling when init or/and limit are not constant | 504 // Protect against over-unrolling when init or/and limit are not constant |
487 // (so that trip_count's init value is maxint) but iv range is known. | 505 // (so that trip_count's init value is maxint) but iv range is known. |
488 if( init_n == NULL || !init_n->is_Con() || | 506 if (init_n == NULL || !init_n->is_Con() || |
489 limit_n == NULL || !limit_n->is_Con() ) { | 507 limit_n == NULL || !limit_n->is_Con()) { |
490 Node* phi = cl->phi(); | 508 Node* phi = cl->phi(); |
491 if( phi != NULL ) { | 509 if (phi != NULL) { |
492 assert(phi->is_Phi() && phi->in(0) == _head, "Counted loop should have iv phi."); | 510 assert(phi->is_Phi() && phi->in(0) == _head, "Counted loop should have iv phi."); |
493 const TypeInt* iv_type = phase->_igvn.type(phi)->is_int(); | 511 const TypeInt* iv_type = phase->_igvn.type(phi)->is_int(); |
494 int next_stride = cl->stride_con() * 2; // stride after this unroll | 512 int next_stride = cl->stride_con() * 2; // stride after this unroll |
495 if( next_stride > 0 ) { | 513 if (next_stride > 0) { |
496 if( iv_type->_lo + next_stride <= iv_type->_lo || // overflow | 514 if (iv_type->_lo + next_stride <= iv_type->_lo || // overflow |
497 iv_type->_lo + next_stride > iv_type->_hi ) { | 515 iv_type->_lo + next_stride > iv_type->_hi) { |
498 return false; // over-unrolling | 516 return false; // over-unrolling |
499 } | 517 } |
500 } else if( next_stride < 0 ) { | 518 } else if (next_stride < 0) { |
501 if( iv_type->_hi + next_stride >= iv_type->_hi || // overflow | 519 if (iv_type->_hi + next_stride >= iv_type->_hi || // overflow |
502 iv_type->_hi + next_stride < iv_type->_lo ) { | 520 iv_type->_hi + next_stride < iv_type->_lo) { |
503 return false; // over-unrolling | 521 return false; // over-unrolling |
504 } | 522 } |
505 } | 523 } |
506 } | 524 } |
507 } | 525 } |
509 // Adjust body_size to determine if we unroll or not | 527 // Adjust body_size to determine if we unroll or not |
510 uint body_size = _body.size(); | 528 uint body_size = _body.size(); |
511 // Key test to unroll CaffeineMark's Logic test | 529 // Key test to unroll CaffeineMark's Logic test |
512 int xors_in_loop = 0; | 530 int xors_in_loop = 0; |
513 // Also count ModL, DivL and MulL which expand mightly | 531 // Also count ModL, DivL and MulL which expand mightly |
514 for( uint k = 0; k < _body.size(); k++ ) { | 532 for (uint k = 0; k < _body.size(); k++) { |
515 switch( _body.at(k)->Opcode() ) { | 533 Node* n = _body.at(k); |
516 case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test | 534 switch (n->Opcode()) { |
517 case Op_ModL: body_size += 30; break; | 535 case Op_XorI: xors_in_loop++; break; // CaffeineMark's Logic test |
518 case Op_DivL: body_size += 30; break; | 536 case Op_ModL: body_size += 30; break; |
519 case Op_MulL: body_size += 10; break; | 537 case Op_DivL: body_size += 30; break; |
520 } | 538 case Op_MulL: body_size += 10; break; |
539 case Op_StrComp: | |
540 case Op_StrEquals: | |
541 case Op_StrIndexOf: | |
542 case Op_AryEq: { | |
543 // Do not unroll a loop with String intrinsics code. | |
544 // String intrinsics are large and have loops. | |
545 return false; | |
546 } | |
547 } // switch | |
521 } | 548 } |
522 | 549 |
523 // Check for being too big | 550 // Check for being too big |
524 if( body_size > (uint)LoopUnrollLimit ) { | 551 if (body_size > (uint)LoopUnrollLimit) { |
525 if( xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true; | 552 if (xors_in_loop >= 4 && body_size < (uint)LoopUnrollLimit*4) return true; |
526 // Normal case: loop too big | 553 // Normal case: loop too big |
527 return false; | 554 return false; |
528 } | 555 } |
529 | 556 |
530 // Check for stride being a small enough constant | 557 // Check for stride being a small enough constant |
531 if( abs(cl->stride_con()) > (1<<3) ) return false; | 558 if (abs(cl->stride_con()) > (1<<3)) return false; |
532 | 559 |
533 // Unroll once! (Each trip will soon do double iterations) | 560 // Unroll once! (Each trip will soon do double iterations) |
534 return true; | 561 return true; |
535 } | 562 } |
536 | 563 |