comparison src/share/vm/opto/loopTransform.cpp @ 20804:7848fc12602b

Merge with jdk8u40-b25
author Gilles Duboscq <gilles.m.duboscq@oracle.com>
date Tue, 07 Apr 2015 14:58:49 +0200
parents 52b4284cb496 5b8e0f84f00f
children
comparison
equal deleted inserted replaced
20184:84105dcdb05b 20804:7848fc12602b
267 // Return TRUE or FALSE if the loop should be peeled or not. Peel if we can 267 // Return TRUE or FALSE if the loop should be peeled or not. Peel if we can
268 // make some loop-invariant test (usually a null-check) happen before the loop. 268 // make some loop-invariant test (usually a null-check) happen before the loop.
269 bool IdealLoopTree::policy_peeling( PhaseIdealLoop *phase ) const { 269 bool IdealLoopTree::policy_peeling( PhaseIdealLoop *phase ) const {
270 Node *test = ((IdealLoopTree*)this)->tail(); 270 Node *test = ((IdealLoopTree*)this)->tail();
271 int body_size = ((IdealLoopTree*)this)->_body.size(); 271 int body_size = ((IdealLoopTree*)this)->_body.size();
272 int live_node_count = phase->C->live_nodes();
273 // Peeling does loop cloning which can result in O(N^2) node construction 272 // Peeling does loop cloning which can result in O(N^2) node construction
274 if( body_size > 255 /* Prevent overflow for large body_size */ 273 if( body_size > 255 /* Prevent overflow for large body_size */
275 || (body_size * body_size + live_node_count > MaxNodeLimit) ) { 274 || (body_size * body_size + phase->C->live_nodes()) > phase->C->max_node_limit() ) {
276 return false; // too large to safely clone 275 return false; // too large to safely clone
277 } 276 }
278 while( test != _head ) { // Scan till run off top of loop 277 while( test != _head ) { // Scan till run off top of loop
279 if( test->is_If() ) { // Test? 278 if( test->is_If() ) { // Test?
280 Node *ctrl = phase->get_ctrl(test->in(1)); 279 Node *ctrl = phase->get_ctrl(test->in(1));
599 uint tst_body_size = (new_body_size - EMPTY_LOOP_SIZE) / trip_count + EMPTY_LOOP_SIZE; 598 uint tst_body_size = (new_body_size - EMPTY_LOOP_SIZE) / trip_count + EMPTY_LOOP_SIZE;
600 if (body_size != tst_body_size) // Check for int overflow 599 if (body_size != tst_body_size) // Check for int overflow
601 return false; 600 return false;
602 if (new_body_size > unroll_limit || 601 if (new_body_size > unroll_limit ||
603 // Unrolling can result in a large amount of node construction 602 // Unrolling can result in a large amount of node construction
604 new_body_size >= MaxNodeLimit - (uint) phase->C->live_nodes()) { 603 new_body_size >= phase->C->max_node_limit() - phase->C->live_nodes()) {
605 return false; 604 return false;
606 } 605 }
607 606
608 // Do not unroll a loop with String intrinsics code. 607 // Do not unroll a loop with String intrinsics code.
609 // String intrinsics are large and have loops. 608 // String intrinsics are large and have loops.
880 set_ctrl( n, find_non_split_ctrl(back_ctrl->in(0)) ); 879 set_ctrl( n, find_non_split_ctrl(back_ctrl->in(0)) );
881 } 880 }
882 return n; 881 return n;
883 } 882 }
884 883
884 bool PhaseIdealLoop::cast_incr_before_loop(Node* incr, Node* ctrl, Node* loop) {
885 Node* castii = new (C) CastIINode(incr, TypeInt::INT, true);
886 castii->set_req(0, ctrl);
887 register_new_node(castii, ctrl);
888 for (DUIterator_Fast imax, i = incr->fast_outs(imax); i < imax; i++) {
889 Node* n = incr->fast_out(i);
890 if (n->is_Phi() && n->in(0) == loop) {
891 int nrep = n->replace_edge(incr, castii);
892 return true;
893 }
894 }
895 return false;
896 }
897
885 //------------------------------insert_pre_post_loops-------------------------- 898 //------------------------------insert_pre_post_loops--------------------------
886 // Insert pre and post loops. If peel_only is set, the pre-loop can not have 899 // Insert pre and post loops. If peel_only is set, the pre-loop can not have
887 // more iterations added. It acts as a 'peel' only, no lower-bound RCE, no 900 // more iterations added. It acts as a 'peel' only, no lower-bound RCE, no
888 // alignment. Useful to unroll loops that do no array accesses. 901 // alignment. Useful to unroll loops that do no array accesses.
889 void PhaseIdealLoop::insert_pre_post_loops( IdealLoopTree *loop, Node_List &old_new, bool peel_only ) { 902 void PhaseIdealLoop::insert_pre_post_loops( IdealLoopTree *loop, Node_List &old_new, bool peel_only ) {
1077 visited, clones); 1090 visited, clones);
1078 _igvn.hash_delete(main_phi); 1091 _igvn.hash_delete(main_phi);
1079 main_phi->set_req( LoopNode::EntryControl, fallpre ); 1092 main_phi->set_req( LoopNode::EntryControl, fallpre );
1080 } 1093 }
1081 } 1094 }
1095
1096 // Nodes inside the loop may be control dependent on a predicate
1097 // that was moved before the preloop. If the back branch of the main
1098 // or post loops becomes dead, those nodes won't be dependent on the
1099 // test that guards that loop nest anymore which could lead to an
1100 // incorrect array access because it executes independently of the
1101 // test that was guarding the loop nest. We add a special CastII on
1102 // the if branch that enters the loop, between the input induction
1103 // variable value and the induction variable Phi to preserve correct
1104 // dependencies.
1105
1106 // CastII for the post loop:
1107 bool inserted = cast_incr_before_loop(zer_opaq->in(1), zer_taken, post_head);
1108 assert(inserted, "no castII inserted");
1109
1110 // CastII for the main loop:
1111 inserted = cast_incr_before_loop(pre_incr, min_taken, main_head);
1112 assert(inserted, "no castII inserted");
1082 1113
1083 // Step B4: Shorten the pre-loop to run only 1 iteration (for now). 1114 // Step B4: Shorten the pre-loop to run only 1 iteration (for now).
1084 // RCE and alignment may change this later. 1115 // RCE and alignment may change this later.
1085 Node *cmp_end = pre_end->cmp_node(); 1116 Node *cmp_end = pre_end->cmp_node();
1086 assert( cmp_end->in(2) == limit, "" ); 1117 assert( cmp_end->in(2) == limit, "" );
2285 } 2316 }
2286 } 2317 }
2287 2318
2288 // Skip next optimizations if running low on nodes. Note that 2319 // Skip next optimizations if running low on nodes. Note that
2289 // policy_unswitching and policy_maximally_unroll have this check. 2320 // policy_unswitching and policy_maximally_unroll have this check.
2290 uint nodes_left = MaxNodeLimit - (uint) phase->C->live_nodes(); 2321 int nodes_left = phase->C->max_node_limit() - phase->C->live_nodes();
2291 if ((2 * _body.size()) > nodes_left) { 2322 if ((int)(2 * _body.size()) > nodes_left) {
2292 return true; 2323 return true;
2293 } 2324 }
2294 2325
2295 // Counted loops may be peeled, may need some iterations run up 2326 // Counted loops may be peeled, may need some iterations run up
2296 // front for RCE, and may want to align loop refs to a cache 2327 // front for RCE, and may want to align loop refs to a cache