@@ -4511,23 +4511,6 @@ bool PhaseIdealLoop::process_expensive_nodes() {
4511
4511
return progress;
4512
4512
}
4513
4513
4514
- #ifdef ASSERT
4515
- // Goes over all children of the root of the loop tree. Check if any of them have a path
4516
- // down to Root, that does not go via a NeverBranch exit.
4517
- bool PhaseIdealLoop::only_has_infinite_loops () {
4518
- ResourceMark rm;
4519
- Unique_Node_List worklist;
4520
- // start traversal at all loop heads of first-level loops
4521
- for (IdealLoopTree* l = _ltree_root->_child ; l != nullptr ; l = l->_next ) {
4522
- Node* head = l->_head ;
4523
- assert (head->is_Region (), " " );
4524
- worklist.push (head);
4525
- }
4526
- return RegionNode::are_all_nodes_in_infinite_subgraph (worklist);
4527
- }
4528
- #endif
4529
-
4530
-
4531
4514
// =============================================================================
4532
4515
// ----------------------------build_and_optimize-------------------------------
4533
4516
// Create a PhaseLoop. Build the ideal Loop tree. Map each Ideal Node to
@@ -4586,13 +4569,9 @@ void PhaseIdealLoop::build_and_optimize() {
4586
4569
return ;
4587
4570
}
4588
4571
4589
- // Verify that the has_loops() flag set at parse time is consistent
4590
- // with the just built loop tree. With infinite loops, it could be
4591
- // that one pass of loop opts only finds infinite loops, clears the
4592
- // has_loops() flag but adds NeverBranch nodes so the next loop opts
4593
- // verification pass finds a non empty loop tree. When the back edge
4572
+ // Verify that the has_loops() flag set at parse time is consistent with the just built loop tree. When the back edge
4594
4573
// is an exception edge, parsing doesn't set has_loops().
4595
- assert (_ltree_root->_child == nullptr || C->has_loops () || only_has_infinite_loops () || C->has_exception_backedge (), " parsing found no loops but there are some" );
4574
+ assert (_ltree_root->_child == nullptr || C->has_loops () || C->has_exception_backedge (), " parsing found no loops but there are some" );
4596
4575
// No loops after all
4597
4576
if ( !_ltree_root->_child && !_verify_only ) C->set_has_loops (false );
4598
4577
@@ -5425,7 +5404,7 @@ void PhaseIdealLoop::build_loop_tree() {
5425
5404
if ( bltstack.length () == stack_size ) {
5426
5405
// There were no additional children, post visit node now
5427
5406
(void )bltstack.pop (); // Remove node from stack
5428
- pre_order = build_loop_tree_impl ( n, pre_order );
5407
+ pre_order = build_loop_tree_impl (n, pre_order);
5429
5408
// Check for bailout
5430
5409
if (C->failing ()) {
5431
5410
return ;
@@ -5443,7 +5422,7 @@ void PhaseIdealLoop::build_loop_tree() {
5443
5422
}
5444
5423
5445
5424
// ------------------------------build_loop_tree_impl---------------------------
5446
- int PhaseIdealLoop::build_loop_tree_impl ( Node * n, int pre_order ) {
5425
+ int PhaseIdealLoop::build_loop_tree_impl (Node* n, int pre_order) {
5447
5426
// ---- Post-pass Work ----
5448
5427
// Pre-walked but not post-walked nodes need a pre_order number.
5449
5428
@@ -5454,24 +5433,24 @@ int PhaseIdealLoop::build_loop_tree_impl( Node *n, int pre_order ) {
5454
5433
// for it. Then find the tightest enclosing loop for the self Node.
5455
5434
for (DUIterator_Fast imax, i = n->fast_outs (imax); i < imax; i++) {
5456
5435
Node* m = n->fast_out (i); // Child
5457
- if ( n == m ) continue ; // Ignore control self-cycles
5458
- if ( !m->is_CFG () ) continue ;// Ignore non-CFG edges
5436
+ if ( n == m) continue ; // Ignore control self-cycles
5437
+ if ( !m->is_CFG ()) continue ;// Ignore non-CFG edges
5459
5438
5460
5439
IdealLoopTree *l; // Child's loop
5461
- if ( !is_postvisited (m) ) { // Child visited but not post-visited?
5440
+ if ( !is_postvisited (m)) { // Child visited but not post-visited?
5462
5441
// Found a backedge
5463
- assert ( get_preorder (m) < pre_order, " should be backedge" );
5442
+ assert (get_preorder (m) < pre_order, " should be backedge" );
5464
5443
// Check for the RootNode, which is already a LoopNode and is allowed
5465
5444
// to have multiple "backedges".
5466
- if ( m == C->root ()) { // Found the root?
5445
+ if ( m == C->root ()) { // Found the root?
5467
5446
l = _ltree_root; // Root is the outermost LoopNode
5468
5447
} else { // Else found a nested loop
5469
5448
// Insert a LoopNode to mark this loop.
5470
5449
l = new IdealLoopTree (this , m, n);
5471
5450
} // End of Else found a nested loop
5472
- if ( !has_loop (m) ) // If 'm' does not already have a loop set
5451
+ if ( !has_loop (m)) { // If 'm' does not already have a loop set
5473
5452
set_loop (m, l); // Set loop header to loop now
5474
-
5453
+ }
5475
5454
} else { // Else not a nested loop
5476
5455
if (!_loop_or_ctrl[m->_idx ]) continue ; // Dead code has no loop
5477
5456
IdealLoopTree* m_loop = get_loop (m);
@@ -5480,23 +5459,17 @@ int PhaseIdealLoop::build_loop_tree_impl( Node *n, int pre_order ) {
5480
5459
// is a member of some outer enclosing loop. Since there are no
5481
5460
// shared headers (I've split them already) I only need to go up
5482
5461
// at most 1 level.
5483
- while ( l && l->_head == m ) // Successor heads loop?
5462
+ while ( l && l->_head == m) { // Successor heads loop?
5484
5463
l = l->_parent ; // Move up 1 for me
5464
+ }
5485
5465
// If this loop is not properly parented, then this loop
5486
5466
// has no exit path out, i.e. its an infinite loop.
5487
- if ( !l ) {
5467
+ if (!l ) {
5488
5468
// Make loop "reachable" from root so the CFG is reachable. Basically
5489
5469
// insert a bogus loop exit that is never taken. 'm', the loop head,
5490
5470
// points to 'n', one (of possibly many) fall-in paths. There may be
5491
5471
// many backedges as well.
5492
5472
5493
- // Here I set the loop to be the root loop. I could have, after
5494
- // inserting a bogus loop exit, restarted the recursion and found my
5495
- // new loop exit. This would make the infinite loop a first-class
5496
- // loop and it would then get properly optimized. What's the use of
5497
- // optimizing an infinite loop?
5498
- l = _ltree_root; // Oops, found infinite loop
5499
-
5500
5473
if (!_verify_only) {
5501
5474
// Insert the NeverBranch between 'm' and it's control user.
5502
5475
NeverBranchNode *iff = new NeverBranchNode ( m );
@@ -5520,7 +5493,7 @@ int PhaseIdealLoop::build_loop_tree_impl( Node *n, int pre_order ) {
5520
5493
// Now create the never-taken loop exit
5521
5494
Node *if_f = new CProjNode ( iff, 1 );
5522
5495
_igvn.register_new_node_with_optimizer (if_f);
5523
- set_loop (if_f, l );
5496
+ set_loop (if_f, _ltree_root );
5524
5497
// Find frame ptr for Halt. Relies on the optimizer
5525
5498
// V-N'ing. Easier and quicker than searching through
5526
5499
// the program structure.
@@ -5529,10 +5502,27 @@ int PhaseIdealLoop::build_loop_tree_impl( Node *n, int pre_order ) {
5529
5502
// Halt & Catch Fire
5530
5503
Node* halt = new HaltNode (if_f, frame, " never-taken loop exit reached" );
5531
5504
_igvn.register_new_node_with_optimizer (halt);
5532
- set_loop (halt, l );
5505
+ set_loop (halt, _ltree_root );
5533
5506
_igvn.add_input_to (C->root (), halt);
5534
5507
}
5535
5508
set_loop (C->root (), _ltree_root);
5509
+ // move to outer most loop with same header
5510
+ l = m_loop;
5511
+ while (true ) {
5512
+ IdealLoopTree* next = l->_parent ;
5513
+ if (next == nullptr || next->_head != m) {
5514
+ break ;
5515
+ }
5516
+ l = next;
5517
+ }
5518
+ // properly insert infinite loop in loop tree
5519
+ sort (_ltree_root, l);
5520
+ // fix child link from parent
5521
+ IdealLoopTree* p = l->_parent ;
5522
+ l->_next = p->_child ;
5523
+ p->_child = l;
5524
+ // code below needs enclosing loop
5525
+ l = l->_parent ;
5536
5526
}
5537
5527
}
5538
5528
if (is_postvisited (l->_head )) {
@@ -5586,7 +5576,7 @@ int PhaseIdealLoop::build_loop_tree_impl( Node *n, int pre_order ) {
5586
5576
assert ( get_loop (n) == innermost, " " );
5587
5577
IdealLoopTree *p = innermost->_parent ;
5588
5578
IdealLoopTree *l = innermost;
5589
- while ( p && l->_head == n ) {
5579
+ while ( p && l->_head == n) {
5590
5580
l->_next = p->_child ; // Put self on parents 'next child'
5591
5581
p->_child = l; // Make self as first child of parent
5592
5582
l = p; // Now walk up the parent chain
@@ -5600,7 +5590,7 @@ int PhaseIdealLoop::build_loop_tree_impl( Node *n, int pre_order ) {
5600
5590
// Record tightest enclosing loop for self. Mark as post-visited.
5601
5591
set_loop (n, innermost);
5602
5592
// Also record has_call flag early on
5603
- if ( innermost ) {
5593
+ if ( innermost) {
5604
5594
if ( n->is_Call () && !n->is_CallLeaf () && !n->is_macro () ) {
5605
5595
// Do not count uncommon calls
5606
5596
if ( !n->is_CallStaticJava () || !n->as_CallStaticJava ()->_name ) {
0 commit comments