@@ -3531,26 +3531,27 @@ bool IdealLoopTree::beautify_loops( PhaseIdealLoop *phase ) {
3531
3531
}
3532
3532
3533
3533
// ------------------------------allpaths_check_safepts----------------------------
3534
- // Allpaths backwards scan from loop tail, terminating each path at first safepoint
3535
- // encountered. Helper for check_safepts.
3534
+ // Allpaths backwards scan. Starting at the head, traversing all backedges, and the body. Terminating each path at first
3535
+ // safepoint encountered. Helper for check_safepts.
3536
3536
void IdealLoopTree::allpaths_check_safepts (VectorSet &visited, Node_List &stack) {
3537
3537
assert (stack.size () == 0 , " empty stack" );
3538
- stack.push (_tail );
3538
+ stack.push (_head );
3539
3539
visited.clear ();
3540
- visited.set (_tail ->_idx );
3540
+ visited.set (_head ->_idx );
3541
3541
while (stack.size () > 0 ) {
3542
3542
Node* n = stack.pop ();
3543
3543
if (n->is_Call () && n->as_Call ()->guaranteed_safepoint ()) {
3544
3544
// Terminate this path
3545
3545
} else if (n->Opcode () == Op_SafePoint) {
3546
3546
if (_phase->get_loop (n) != this ) {
3547
3547
if (_required_safept == nullptr ) _required_safept = new Node_List ();
3548
- _required_safept->push (n); // save the one closest to the tail
3548
+ // save the first we run into on that path: closest to the tail if the head has a single backedge
3549
+ _required_safept->push (n);
3549
3550
}
3550
3551
// Terminate this path
3551
3552
} else {
3552
3553
uint start = n->is_Region () ? 1 : 0 ;
3553
- uint end = n->is_Region () && !n->is_Loop () ? n->req () : start + 1 ;
3554
+ uint end = n->is_Region () && ( !n->is_Loop () || n == _head ) ? n->req () : start + 1 ;
3554
3555
for (uint i = start; i < end; i++) {
3555
3556
Node* in = n->in (i);
3556
3557
assert (in->is_CFG (), " must be" );
@@ -3622,53 +3623,55 @@ void IdealLoopTree::check_safepts(VectorSet &visited, Node_List &stack) {
3622
3623
if (_child) _child->check_safepts (visited, stack);
3623
3624
if (_next) _next ->check_safepts (visited, stack);
3624
3625
3625
- if (!_head->is_CountedLoop () && !_has_sfpt && _parent != nullptr && !_irreducible ) {
3626
+ if (!_head->is_CountedLoop () && !_has_sfpt && _parent != nullptr ) {
3626
3627
bool has_call = false ; // call on dom-path
3627
3628
bool has_local_ncsfpt = false ; // ncsfpt on dom-path at this loop depth
3628
3629
Node* nonlocal_ncsfpt = nullptr ; // ncsfpt on dom-path at a deeper depth
3629
- // Scan the dom-path nodes from tail to head
3630
- for (Node* n = tail (); n != _head; n = _phase->idom (n)) {
3631
- if (n->is_Call () && n->as_Call ()->guaranteed_safepoint ()) {
3632
- has_call = true ;
3633
- _has_sfpt = 1 ; // Then no need for a safept!
3634
- break ;
3635
- } else if (n->Opcode () == Op_SafePoint) {
3636
- if (_phase->get_loop (n) == this ) {
3637
- has_local_ncsfpt = true ;
3630
+ if (!_irreducible) {
3631
+ // Scan the dom-path nodes from tail to head
3632
+ for (Node* n = tail (); n != _head; n = _phase->idom (n)) {
3633
+ if (n->is_Call () && n->as_Call ()->guaranteed_safepoint ()) {
3634
+ has_call = true ;
3635
+ _has_sfpt = 1 ; // Then no need for a safept!
3638
3636
break ;
3639
- }
3640
- if (nonlocal_ncsfpt == nullptr ) {
3641
- nonlocal_ncsfpt = n; // save the one closest to the tail
3642
- }
3643
- } else {
3644
- IdealLoopTree* nlpt = _phase->get_loop (n);
3645
- if (this != nlpt) {
3646
- // If at an inner loop tail, see if the inner loop has already
3647
- // recorded seeing a call on the dom-path (and stop.) If not,
3648
- // jump to the head of the inner loop.
3649
- assert (is_member (nlpt), " nested loop" );
3650
- Node* tail = nlpt->_tail ;
3651
- if (tail->in (0 )->is_If ()) tail = tail->in (0 );
3652
- if (n == tail) {
3653
- // If inner loop has call on dom-path, so does outer loop
3654
- if (nlpt->_has_sfpt ) {
3655
- has_call = true ;
3656
- _has_sfpt = 1 ;
3657
- break ;
3658
- }
3659
- // Skip to head of inner loop
3660
- assert (_phase->is_dominator (_head, nlpt->_head ), " inner head dominated by outer head" );
3661
- n = nlpt->_head ;
3662
- if (_head == n) {
3663
- // this and nlpt (inner loop) have the same loop head. This should not happen because
3664
- // during beautify_loops we call merge_many_backedges. However, infinite loops may not
3665
- // have been attached to the loop-tree during build_loop_tree before beautify_loops,
3666
- // but then attached in the build_loop_tree afterwards, and so still have unmerged
3667
- // backedges. Check if we are indeed in an infinite subgraph, and terminate the scan,
3668
- // since we have reached the loop head of this.
3669
- assert (_head->as_Region ()->is_in_infinite_subgraph (),
3670
- " only expect unmerged backedges in infinite loops" );
3671
- break ;
3637
+ } else if (n->Opcode () == Op_SafePoint) {
3638
+ if (_phase->get_loop (n) == this ) {
3639
+ has_local_ncsfpt = true ;
3640
+ break ;
3641
+ }
3642
+ if (nonlocal_ncsfpt == nullptr ) {
3643
+ nonlocal_ncsfpt = n; // save the one closest to the tail
3644
+ }
3645
+ } else {
3646
+ IdealLoopTree* nlpt = _phase->get_loop (n);
3647
+ if (this != nlpt) {
3648
+ // If at an inner loop tail, see if the inner loop has already
3649
+ // recorded seeing a call on the dom-path (and stop.) If not,
3650
+ // jump to the head of the inner loop.
3651
+ assert (is_member (nlpt), " nested loop" );
3652
+ Node* tail = nlpt->_tail ;
3653
+ if (tail->in (0 )->is_If ()) tail = tail->in (0 );
3654
+ if (n == tail) {
3655
+ // If inner loop has call on dom-path, so does outer loop
3656
+ if (nlpt->_has_sfpt ) {
3657
+ has_call = true ;
3658
+ _has_sfpt = 1 ;
3659
+ break ;
3660
+ }
3661
+ // Skip to head of inner loop
3662
+ assert (_phase->is_dominator (_head, nlpt->_head ), " inner head dominated by outer head" );
3663
+ n = nlpt->_head ;
3664
+ if (_head == n) {
3665
+ // this and nlpt (inner loop) have the same loop head. This should not happen because
3666
+ // during beautify_loops we call merge_many_backedges. However, infinite loops may not
3667
+ // have been attached to the loop-tree during build_loop_tree before beautify_loops,
3668
+ // but then attached in the build_loop_tree afterwards, and so still have unmerged
3669
+ // backedges. Check if we are indeed in an infinite subgraph, and terminate the scan,
3670
+ // since we have reached the loop head of this.
3671
+ assert (_head->as_Region ()->is_in_infinite_subgraph (),
3672
+ " only expect unmerged backedges in infinite loops" );
3673
+ break ;
3674
+ }
3672
3675
}
3673
3676
}
3674
3677
}
0 commit comments