src/share/vm/opto/loopTransform.cpp

Print this page
rev 4329 : [mq]: JDK-8009181


 871 // Insert pre and post loops.  If peel_only is set, the pre-loop can not have
 872 // more iterations added.  It acts as a 'peel' only, no lower-bound RCE, no
 873 // alignment.  Useful to unroll loops that do no array accesses.
 874 void PhaseIdealLoop::insert_pre_post_loops( IdealLoopTree *loop, Node_List &old_new, bool peel_only ) {
 875 
 876 #ifndef PRODUCT
 877   if (TraceLoopOpts) {
 878     if (peel_only)
 879       tty->print("PeelMainPost ");
 880     else
 881       tty->print("PreMainPost  ");
 882     loop->dump_head();
 883   }
 884 #endif
 885   C->set_major_progress();
 886 
 887   // Find common pieces of the loop being guarded with pre & post loops
 888   CountedLoopNode *main_head = loop->_head->as_CountedLoop();
 889   assert( main_head->is_normal_loop(), "" );
 890   CountedLoopEndNode *main_end = main_head->loopexit();

 891   assert( main_end->outcnt() == 2, "1 true, 1 false path only" );
 892   uint dd_main_head = dom_depth(main_head);
 893   uint max = main_head->outcnt();
 894 
 895   Node *pre_header= main_head->in(LoopNode::EntryControl);
 896   Node *init      = main_head->init_trip();
 897   Node *incr      = main_end ->incr();
 898   Node *limit     = main_end ->limit();
 899   Node *stride    = main_end ->stride();
 900   Node *cmp       = main_end ->cmp_node();
 901   BoolTest::mask b_test = main_end->test_trip();
 902 
 903   // Need only 1 user of 'bol' because I will be hacking the loop bounds.
 904   Node *bol = main_end->in(CountedLoopEndNode::TestValue);
 905   if( bol->outcnt() != 1 ) {
 906     bol = bol->clone();
 907     register_new_node(bol,main_end->in(CountedLoopEndNode::TestControl));
 908     _igvn.hash_delete(main_end);
 909     main_end->set_req(CountedLoopEndNode::TestValue, bol);
 910   }


2537     msg_node = store;
2538   }
2539 
2540   if (msg != NULL) {
2541 #ifndef PRODUCT
2542     if (TraceOptimizeFill) {
2543       tty->print_cr("not fill intrinsic: %s", msg);
2544       if (msg_node != NULL) msg_node->dump();
2545     }
2546 #endif
2547     return false;
2548   }
2549 
2550   // No make sure all the other nodes in the loop can be handled
2551   VectorSet ok(Thread::current()->resource_area());
2552 
2553   // store related values are ok
2554   ok.set(store->_idx);
2555   ok.set(store->in(MemNode::Memory)->_idx);
2556 



2557   // Loop structure is ok
2558   ok.set(head->_idx);
2559   ok.set(head->loopexit()->_idx);
2560   ok.set(head->phi()->_idx);
2561   ok.set(head->incr()->_idx);
2562   ok.set(head->loopexit()->cmp_node()->_idx);
2563   ok.set(head->loopexit()->in(1)->_idx);
2564 
2565   // Address elements are ok
2566   if (con)   ok.set(con->_idx);
2567   if (shift) ok.set(shift->_idx);
2568   if (conv)  ok.set(conv->_idx);
2569 
2570   for (uint i = 0; msg == NULL && i < lpt->_body.size(); i++) {
2571     Node* n = lpt->_body.at(i);
2572     if (n->outcnt() == 0) continue; // Ignore dead
2573     if (ok.test(n->_idx)) continue;
2574     // Backedge projection is ok
2575     if (n->is_IfTrue() && n->in(0) == head->loopexit()) continue;
2576     if (!n->is_AddP()) {
2577       msg = "unhandled node";
2578       msg_node = n;
2579       break;
2580     }
2581   }
2582 
2583   // Make sure no unexpected values are used outside the loop
2584   for (uint i = 0; msg == NULL && i < lpt->_body.size(); i++) {
2585     Node* n = lpt->_body.at(i);
2586     // These values can be replaced with other nodes if they are used
2587     // outside the loop.
2588     if (n == store || n == head->loopexit() || n == head->incr() || n == store->in(MemNode::Memory)) continue;
2589     for (SimpleDUIterator iter(n); iter.has_next(); iter.next()) {
2590       Node* use = iter.get();
2591       if (!lpt->_body.contains(use)) {
2592         msg = "node is used outside loop";
2593         // lpt->_body.dump();
2594         msg_node = n;
2595         break;
2596       }
2597     }
2598   }
2599 
2600 #ifdef ASSERT
2601   if (TraceOptimizeFill) {
2602     if (msg != NULL) {
2603       tty->print_cr("no fill intrinsic: %s", msg);
2604       if (msg_node != NULL) msg_node->dump();
2605     } else {
2606       tty->print_cr("fill intrinsic for:");
2607     }
2608     store->dump();




 871 // Insert pre and post loops.  If peel_only is set, the pre-loop can not have
 872 // more iterations added.  It acts as a 'peel' only, no lower-bound RCE, no
 873 // alignment.  Useful to unroll loops that do no array accesses.
 874 void PhaseIdealLoop::insert_pre_post_loops( IdealLoopTree *loop, Node_List &old_new, bool peel_only ) {
 875 
 876 #ifndef PRODUCT
 877   if (TraceLoopOpts) {
 878     if (peel_only)
 879       tty->print("PeelMainPost ");
 880     else
 881       tty->print("PreMainPost  ");
 882     loop->dump_head();
 883   }
 884 #endif
 885   C->set_major_progress();
 886 
 887   // Find common pieces of the loop being guarded with pre & post loops
 888   CountedLoopNode *main_head = loop->_head->as_CountedLoop();
 889   assert( main_head->is_normal_loop(), "" );
 890   CountedLoopEndNode *main_end = main_head->loopexit();
 891   guarantee(main_end != NULL, "no loop exit node");
 892   assert( main_end->outcnt() == 2, "1 true, 1 false path only" );
 893   uint dd_main_head = dom_depth(main_head);
 894   uint max = main_head->outcnt();
 895 
 896   Node *pre_header= main_head->in(LoopNode::EntryControl);
 897   Node *init      = main_head->init_trip();
 898   Node *incr      = main_end ->incr();
 899   Node *limit     = main_end ->limit();
 900   Node *stride    = main_end ->stride();
 901   Node *cmp       = main_end ->cmp_node();
 902   BoolTest::mask b_test = main_end->test_trip();
 903 
 904   // Need only 1 user of 'bol' because I will be hacking the loop bounds.
 905   Node *bol = main_end->in(CountedLoopEndNode::TestValue);
 906   if( bol->outcnt() != 1 ) {
 907     bol = bol->clone();
 908     register_new_node(bol,main_end->in(CountedLoopEndNode::TestControl));
 909     _igvn.hash_delete(main_end);
 910     main_end->set_req(CountedLoopEndNode::TestValue, bol);
 911   }


2538     msg_node = store;
2539   }
2540 
2541   if (msg != NULL) {
2542 #ifndef PRODUCT
2543     if (TraceOptimizeFill) {
2544       tty->print_cr("not fill intrinsic: %s", msg);
2545       if (msg_node != NULL) msg_node->dump();
2546     }
2547 #endif
2548     return false;
2549   }
2550 
2551   // No make sure all the other nodes in the loop can be handled
2552   VectorSet ok(Thread::current()->resource_area());
2553 
2554   // store related values are ok
2555   ok.set(store->_idx);
2556   ok.set(store->in(MemNode::Memory)->_idx);
2557 
2558   CountedLoopEndNode* loop_exit = head->loopexit();
2559   guarantee(loop_exit != NULL, "no loop exit node");
2560 
2561   // Loop structure is ok
2562   ok.set(head->_idx);
2563   ok.set(head_exit->_idx);
2564   ok.set(head->phi()->_idx);
2565   ok.set(head->incr()->_idx);
2566   ok.set(loop_exit->cmp_node()->_idx);
2567   ok.set(loop_exit->in(1)->_idx);
2568 
2569   // Address elements are ok
2570   if (con)   ok.set(con->_idx);
2571   if (shift) ok.set(shift->_idx);
2572   if (conv)  ok.set(conv->_idx);
2573 
2574   for (uint i = 0; msg == NULL && i < lpt->_body.size(); i++) {
2575     Node* n = lpt->_body.at(i);
2576     if (n->outcnt() == 0) continue; // Ignore dead
2577     if (ok.test(n->_idx)) continue;
2578     // Backedge projection is ok
2579     if (n->is_IfTrue() && n->in(0) == loop_exit) continue;
2580     if (!n->is_AddP()) {
2581       msg = "unhandled node";
2582       msg_node = n;
2583       break;
2584     }
2585   }
2586 
2587   // Make sure no unexpected values are used outside the loop
2588   for (uint i = 0; msg == NULL && i < lpt->_body.size(); i++) {
2589     Node* n = lpt->_body.at(i);
2590     // These values can be replaced with other nodes if they are used
2591     // outside the loop.
2592     if (n == store || n == loop_exit || n == head->incr() || n == store->in(MemNode::Memory)) continue;
2593     for (SimpleDUIterator iter(n); iter.has_next(); iter.next()) {
2594       Node* use = iter.get();
2595       if (!lpt->_body.contains(use)) {
2596         msg = "node is used outside loop";
2597         // lpt->_body.dump();
2598         msg_node = n;
2599         break;
2600       }
2601     }
2602   }
2603 
2604 #ifdef ASSERT
2605   if (TraceOptimizeFill) {
2606     if (msg != NULL) {
2607       tty->print_cr("no fill intrinsic: %s", msg);
2608       if (msg_node != NULL) msg_node->dump();
2609     } else {
2610       tty->print_cr("fill intrinsic for:");
2611     }
2612     store->dump();