src/share/vm/opto/loopPredicate.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/share/vm/opto

src/share/vm/opto/loopPredicate.cpp

Print this page
rev 8157 : 8078426: mb/jvm/compiler/InterfaceCalls/testAC2 - assert(predicate_proj == 0L) failed: only one predicate entry expected
Summary: split if finds predicates on several incoming paths when unswitched's loops are optimized out
Reviewed-by:
rev 9360 : 8137168: Replace IfNode with a new RangeCheckNode for range checks
Summary: new RangeCheckNode to enable optimization of explicit library level range checks
Reviewed-by:


  74 //   v    v        v                           |          v
  75 //     rgn       loop                          |         iff
  76 //      |                                      |        /     \
  77 //      |                                      |       /       \
  78 //      v                                      |      v         v
  79 // uncommon_trap                               | uncommon_proj cont_proj
  80 //                                           \  \    |           |
  81 //                                            \  \   |           |
  82 //                                             v  v  v           v
  83 //                                               rgn           loop
  84 //                                                |
  85 //                                                |
  86 //                                                v
  87 //                                           uncommon_trap
  88 //
  89 //
  90 // We will create a region to guard the uct call if there is no one there.
  91 // The true projecttion (if_cont) of the new_iff is returned.
  92 // This code is also used to clone predicates to cloned loops.
  93 ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
  94                                                       Deoptimization::DeoptReason reason) {

  95   assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!");
  96   IfNode* iff = cont_proj->in(0)->as_If();
  97 
  98   ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
  99   Node     *rgn   = uncommon_proj->unique_ctrl_out();
 100   assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
 101 
 102   uint proj_index = 1; // region's edge corresponding to uncommon_proj
 103   if (!rgn->is_Region()) { // create a region to guard the call
 104     assert(rgn->is_Call(), "must be call uct");
 105     CallNode* call = rgn->as_Call();
 106     IdealLoopTree* loop = get_loop(call);
 107     rgn = new RegionNode(1);
 108     rgn->add_req(uncommon_proj);
 109     register_control(rgn, loop, uncommon_proj);
 110     _igvn.replace_input_of(call, 0, rgn);
 111     // When called from beautify_loops() idom is not constructed yet.
 112     if (_idom != NULL) {
 113       set_idom(call, rgn, dom_depth(rgn));
 114     }


 116       Node* n = uncommon_proj->fast_out(i);
 117       if (n->is_Load() || n->is_Store()) {
 118         _igvn.replace_input_of(n, 0, rgn);
 119         --i; --imax;
 120       }
 121     }
 122   } else {
 123     // Find region's edge corresponding to uncommon_proj
 124     for (; proj_index < rgn->req(); proj_index++)
 125       if (rgn->in(proj_index) == uncommon_proj) break;
 126     assert(proj_index < rgn->req(), "sanity");
 127   }
 128 
 129   Node* entry = iff->in(0);
 130   if (new_entry != NULL) {
 131     // Clonning the predicate to new location.
 132     entry = new_entry;
 133   }
 134   // Create new_iff
 135   IdealLoopTree* lp = get_loop(entry);
 136   IfNode *new_iff = iff->clone()->as_If();
 137   new_iff->set_req(0, entry);





 138   register_control(new_iff, lp, entry);
 139   Node *if_cont = new IfTrueNode(new_iff);
 140   Node *if_uct  = new IfFalseNode(new_iff);
 141   if (cont_proj->is_IfFalse()) {
 142     // Swap
 143     Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
 144   }
 145   register_control(if_cont, lp, new_iff);
 146   register_control(if_uct, get_loop(rgn), new_iff);
 147 
 148   // if_uct to rgn
 149   _igvn.hash_delete(rgn);
 150   rgn->add_req(if_uct);
 151   // When called from beautify_loops() idom is not constructed yet.
 152   if (_idom != NULL) {
 153     Node* ridom = idom(rgn);
 154     Node* nrdom = dom_lca(ridom, new_iff);
 155     set_idom(rgn, nrdom, dom_depth(rgn));
 156   }
 157 


 166       _igvn.rehash_node_delayed(use);
 167       use->add_req(use->in(proj_index));
 168       has_phi = true;
 169     }
 170   }
 171   assert(!has_phi || rgn->req() > 3, "no phis when region is created");
 172 
 173   if (new_entry == NULL) {
 174     // Attach if_cont to iff
 175     _igvn.replace_input_of(iff, 0, if_cont);
 176     if (_idom != NULL) {
 177       set_idom(iff, if_cont, dom_depth(iff));
 178     }
 179   }
 180   return if_cont->as_Proj();
 181 }
 182 
 183 //------------------------------create_new_if_for_predicate------------------------
 184 // Create a new if below new_entry for the predicate to be cloned (IGVN optimization)
 185 ProjNode* PhaseIterGVN::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
 186                                                     Deoptimization::DeoptReason reason) {

 187   assert(new_entry != 0, "only used for clone predicate");
 188   assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!");
 189   IfNode* iff = cont_proj->in(0)->as_If();
 190 
 191   ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
 192   Node     *rgn   = uncommon_proj->unique_ctrl_out();
 193   assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
 194 
 195   uint proj_index = 1; // region's edge corresponding to uncommon_proj
 196   if (!rgn->is_Region()) { // create a region to guard the call
 197     assert(rgn->is_Call(), "must be call uct");
 198     CallNode* call = rgn->as_Call();
 199     rgn = new RegionNode(1);
 200     register_new_node_with_optimizer(rgn);
 201     rgn->add_req(uncommon_proj);
 202     replace_input_of(call, 0, rgn);
 203   } else {
 204     // Find region's edge corresponding to uncommon_proj
 205     for (; proj_index < rgn->req(); proj_index++)
 206       if (rgn->in(proj_index) == uncommon_proj) break;
 207     assert(proj_index < rgn->req(), "sanity");
 208   }
 209 
 210   // Create new_iff in new location.
 211   IfNode *new_iff = iff->clone()->as_If();
 212   new_iff->set_req(0, new_entry);





 213 
 214   register_new_node_with_optimizer(new_iff);
 215   Node *if_cont = new IfTrueNode(new_iff);
 216   Node *if_uct  = new IfFalseNode(new_iff);
 217   if (cont_proj->is_IfFalse()) {
 218     // Swap
 219     Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
 220   }
 221   register_new_node_with_optimizer(if_cont);
 222   register_new_node_with_optimizer(if_uct);
 223 
 224   // if_uct to rgn
 225   hash_delete(rgn);
 226   rgn->add_req(if_uct);
 227 
 228   // If rgn has phis add corresponding new edges which has the same
 229   // value as on original uncommon_proj pass.
 230   assert(rgn->in(rgn->req() -1) == if_uct, "new edge should be last");
 231   bool has_phi = false;
 232   for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) {
 233     Node* use = rgn->fast_out(i);
 234     if (use->is_Phi() && use->outcnt() > 0) {
 235       rehash_node_delayed(use);
 236       use->add_req(use->in(proj_index));
 237       has_phi = true;
 238     }
 239   }
 240   assert(!has_phi || rgn->req() > 3, "no phis when region is created");
 241 
 242   return if_cont->as_Proj();
 243 }
 244 
 245 //--------------------------clone_predicate-----------------------
 246 ProjNode* PhaseIdealLoop::clone_predicate(ProjNode* predicate_proj, Node* new_entry,
 247                                           Deoptimization::DeoptReason reason,
 248                                           PhaseIdealLoop* loop_phase,
 249                                           PhaseIterGVN* igvn) {
 250   ProjNode* new_predicate_proj;
 251   if (loop_phase != NULL) {
 252     new_predicate_proj = loop_phase->create_new_if_for_predicate(predicate_proj, new_entry, reason);
 253   } else {
 254     new_predicate_proj =       igvn->create_new_if_for_predicate(predicate_proj, new_entry, reason);
 255   }
 256   IfNode* iff = new_predicate_proj->in(0)->as_If();
 257   Node* ctrl  = iff->in(0);
 258 
 259   // Match original condition since predicate's projections could be swapped.
 260   assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
 261   Node* opq = new Opaque1Node(igvn->C, predicate_proj->in(0)->in(1)->in(1)->in(1));
 262   igvn->C->add_predicate_opaq(opq);
 263 
 264   Node* bol = new Conv2BNode(opq);
 265   if (loop_phase != NULL) {
 266     loop_phase->register_new_node(opq, ctrl);
 267     loop_phase->register_new_node(bol, ctrl);
 268   } else {
 269     igvn->register_new_node_with_optimizer(opq);
 270     igvn->register_new_node_with_optimizer(bol);
 271   }
 272   igvn->hash_delete(iff);
 273   iff->set_req(1, bol);
 274   return new_predicate_proj;


 697       tty->print("missing predicate:");
 698       loop->dump_head();
 699       head->dump(1);
 700     }
 701 #endif
 702     return false;
 703   }
 704   ConNode* zero = _igvn.intcon(0);
 705   set_ctrl(zero, C->root());
 706 
 707   ResourceArea *area = Thread::current()->resource_area();
 708   Invariance invar(area, loop);
 709 
 710   // Create list of if-projs such that a newer proj dominates all older
 711   // projs in the list, and they all dominate loop->tail()
 712   Node_List if_proj_list(area);
 713   Node *current_proj = loop->tail(); //start from tail
 714   while (current_proj != head) {
 715     if (loop == get_loop(current_proj) && // still in the loop ?
 716         current_proj->is_Proj()        && // is a projection  ?
 717         current_proj->in(0)->Opcode() == Op_If) { // is a if projection ?

 718       if_proj_list.push(current_proj);
 719     }
 720     current_proj = idom(current_proj);
 721   }
 722 
 723   bool hoisted = false; // true if at least one proj is promoted
 724   while (if_proj_list.size() > 0) {
 725     // Following are changed to nonnull when a predicate can be hoisted
 726     ProjNode* new_predicate_proj = NULL;
 727 
 728     ProjNode* proj = if_proj_list.pop()->as_Proj();
 729     IfNode*   iff  = proj->in(0)->as_If();
 730 
 731     if (!proj->is_uncommon_trap_if_pattern(Deoptimization::Reason_none)) {
 732       if (loop->is_loop_exit(iff)) {
 733         // stop processing the remaining projs in the list because the execution of them
 734         // depends on the condition of "iff" (iff->in(1)).
 735         break;
 736       } else {
 737         // Both arms are inside the loop. There are two cases:
 738         // (1) there is one backward branch. In this case, any remaining proj
 739         //     in the if_proj list post-dominates "iff". So, the condition of "iff"
 740         //     does not determine the execution the remining projs directly, and we
 741         //     can safely continue.
 742         // (2) both arms are forwarded, i.e. a diamond shape. In this case, "proj"
 743         //     does not dominate loop->tail(), so it can not be in the if_proj list.
 744         continue;
 745       }
 746     }
 747 
 748     Node*     test = iff->in(1);
 749     if (!test->is_Bool()){ //Conv2B, ...
 750       continue;
 751     }
 752     BoolNode* bol = test->as_Bool();
 753     if (invar.is_invariant(bol)) {
 754       // Invariant test
 755       new_predicate_proj = create_new_if_for_predicate(predicate_proj, NULL,
 756                                                        Deoptimization::Reason_predicate);

 757       Node* ctrl = new_predicate_proj->in(0)->as_If()->in(0);
 758       BoolNode* new_predicate_bol = invar.clone(bol, ctrl)->as_Bool();
 759 
 760       // Negate test if necessary
 761       bool negated = false;
 762       if (proj->_con != predicate_proj->_con) {
 763         new_predicate_bol = new BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate());
 764         register_new_node(new_predicate_bol, ctrl);
 765         negated = true;
 766       }
 767       IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If();
 768       _igvn.hash_delete(new_predicate_iff);
 769       new_predicate_iff->set_req(1, new_predicate_bol);
 770 #ifndef PRODUCT
 771       if (TraceLoopPredicate) {
 772         tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx);
 773         loop->dump_head();
 774       } else if (TraceLoopOpts) {
 775         tty->print("Predicate IC ");
 776         loop->dump_head();


 780       // Range check for counted loops
 781       const Node*    cmp    = bol->in(1)->as_Cmp();
 782       Node*          idx    = cmp->in(1);
 783       assert(!invar.is_invariant(idx), "index is variant");
 784       Node* rng = cmp->in(2);
 785       assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be");
 786       assert(invar.is_invariant(rng), "range must be invariant");
 787       int scale    = 1;
 788       Node* offset = zero;
 789       bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset);
 790       assert(ok, "must be index expression");
 791 
 792       Node* init    = cl->init_trip();
 793       Node* limit   = cl->limit();
 794       Node* stride  = cl->stride();
 795 
 796       // Build if's for the upper and lower bound tests.  The
 797       // lower_bound test will dominate the upper bound test and all
 798       // cloned or created nodes will use the lower bound test as
 799       // their declared control.
 800       ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
 801       ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate);
 802       assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate");
 803       Node *ctrl = lower_bound_proj->in(0)->as_If()->in(0);
 804 
 805       // Perform cloning to keep Invariance state correct since the
 806       // late schedule will place invariant things in the loop.
 807       rng = invar.clone(rng, ctrl);
 808       if (offset && offset != zero) {
 809         assert(invar.is_invariant(offset), "offset must be loop invariant");
 810         offset = invar.clone(offset, ctrl);
 811       }
 812 
 813       // Test the lower bound
 814       BoolNode*  lower_bound_bol = rc_predicate(loop, ctrl, scale, offset, init, limit, stride, rng, false);
 815       // Negate test if necessary
 816       bool negated = false;
 817       if (proj->_con != predicate_proj->_con) {
 818         lower_bound_bol = new BoolNode(lower_bound_bol->in(1), lower_bound_bol->_test.negate());
 819         register_new_node(lower_bound_bol, ctrl);
 820         negated = true;
 821       }




  74 //   v    v        v                           |          v
  75 //     rgn       loop                          |         iff
  76 //      |                                      |        /     \
  77 //      |                                      |       /       \
  78 //      v                                      |      v         v
  79 // uncommon_trap                               | uncommon_proj cont_proj
  80 //                                           \  \    |           |
  81 //                                            \  \   |           |
  82 //                                             v  v  v           v
  83 //                                               rgn           loop
  84 //                                                |
  85 //                                                |
  86 //                                                v
  87 //                                           uncommon_trap
  88 //
  89 //
  90 // We will create a region to guard the uct call if there is no one there.
  91 // The true projecttion (if_cont) of the new_iff is returned.
  92 // This code is also used to clone predicates to cloned loops.
  93 ProjNode* PhaseIdealLoop::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
  94                                                       Deoptimization::DeoptReason reason,
  95                                                       int opcode) {
  96   assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!");
  97   IfNode* iff = cont_proj->in(0)->as_If();
  98 
  99   ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
 100   Node     *rgn   = uncommon_proj->unique_ctrl_out();
 101   assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
 102 
 103   uint proj_index = 1; // region's edge corresponding to uncommon_proj
 104   if (!rgn->is_Region()) { // create a region to guard the call
 105     assert(rgn->is_Call(), "must be call uct");
 106     CallNode* call = rgn->as_Call();
 107     IdealLoopTree* loop = get_loop(call);
 108     rgn = new RegionNode(1);
 109     rgn->add_req(uncommon_proj);
 110     register_control(rgn, loop, uncommon_proj);
 111     _igvn.replace_input_of(call, 0, rgn);
 112     // When called from beautify_loops() idom is not constructed yet.
 113     if (_idom != NULL) {
 114       set_idom(call, rgn, dom_depth(rgn));
 115     }


 117       Node* n = uncommon_proj->fast_out(i);
 118       if (n->is_Load() || n->is_Store()) {
 119         _igvn.replace_input_of(n, 0, rgn);
 120         --i; --imax;
 121       }
 122     }
 123   } else {
 124     // Find region's edge corresponding to uncommon_proj
 125     for (; proj_index < rgn->req(); proj_index++)
 126       if (rgn->in(proj_index) == uncommon_proj) break;
 127     assert(proj_index < rgn->req(), "sanity");
 128   }
 129 
 130   Node* entry = iff->in(0);
 131   if (new_entry != NULL) {
 132     // Clonning the predicate to new location.
 133     entry = new_entry;
 134   }
 135   // Create new_iff
 136   IdealLoopTree* lp = get_loop(entry);
 137   IfNode* new_iff = NULL;
 138   if (opcode == Op_If) {
 139     new_iff = new IfNode(entry, iff->in(1), iff->_prob, iff->_fcnt);
 140   } else {
 141     assert(opcode == Op_RangeCheck, "no other if variant here");
 142     new_iff = new RangeCheckNode(entry, iff->in(1), iff->_prob, iff->_fcnt);
 143   }
 144   register_control(new_iff, lp, entry);
 145   Node *if_cont = new IfTrueNode(new_iff);
 146   Node *if_uct  = new IfFalseNode(new_iff);
 147   if (cont_proj->is_IfFalse()) {
 148     // Swap
 149     Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
 150   }
 151   register_control(if_cont, lp, new_iff);
 152   register_control(if_uct, get_loop(rgn), new_iff);
 153 
 154   // if_uct to rgn
 155   _igvn.hash_delete(rgn);
 156   rgn->add_req(if_uct);
 157   // When called from beautify_loops() idom is not constructed yet.
 158   if (_idom != NULL) {
 159     Node* ridom = idom(rgn);
 160     Node* nrdom = dom_lca(ridom, new_iff);
 161     set_idom(rgn, nrdom, dom_depth(rgn));
 162   }
 163 


 172       _igvn.rehash_node_delayed(use);
 173       use->add_req(use->in(proj_index));
 174       has_phi = true;
 175     }
 176   }
 177   assert(!has_phi || rgn->req() > 3, "no phis when region is created");
 178 
 179   if (new_entry == NULL) {
 180     // Attach if_cont to iff
 181     _igvn.replace_input_of(iff, 0, if_cont);
 182     if (_idom != NULL) {
 183       set_idom(iff, if_cont, dom_depth(iff));
 184     }
 185   }
 186   return if_cont->as_Proj();
 187 }
 188 
 189 //------------------------------create_new_if_for_predicate------------------------
 190 // Create a new if below new_entry for the predicate to be cloned (IGVN optimization)
 191 ProjNode* PhaseIterGVN::create_new_if_for_predicate(ProjNode* cont_proj, Node* new_entry,
 192                                                     Deoptimization::DeoptReason reason,
 193                                                     int opcode) {
 194   assert(new_entry != 0, "only used for clone predicate");
 195   assert(cont_proj->is_uncommon_trap_if_pattern(reason), "must be a uct if pattern!");
 196   IfNode* iff = cont_proj->in(0)->as_If();
 197 
 198   ProjNode *uncommon_proj = iff->proj_out(1 - cont_proj->_con);
 199   Node     *rgn   = uncommon_proj->unique_ctrl_out();
 200   assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
 201 
 202   uint proj_index = 1; // region's edge corresponding to uncommon_proj
 203   if (!rgn->is_Region()) { // create a region to guard the call
 204     assert(rgn->is_Call(), "must be call uct");
 205     CallNode* call = rgn->as_Call();
 206     rgn = new RegionNode(1);
 207     register_new_node_with_optimizer(rgn);
 208     rgn->add_req(uncommon_proj);
 209     replace_input_of(call, 0, rgn);
 210   } else {
 211     // Find region's edge corresponding to uncommon_proj
 212     for (; proj_index < rgn->req(); proj_index++)
 213       if (rgn->in(proj_index) == uncommon_proj) break;
 214     assert(proj_index < rgn->req(), "sanity");
 215   }
 216 
 217   // Create new_iff in new location.
 218   IfNode* new_iff = NULL;
 219   if (opcode == Op_If) {
 220     new_iff = new IfNode(new_entry, iff->in(1), iff->_prob, iff->_fcnt);
 221   } else {
 222     assert(opcode == Op_RangeCheck, "no other if variant here");
 223     new_iff = new RangeCheckNode(new_entry, iff->in(1), iff->_prob, iff->_fcnt);
 224   }
 225 
 226   register_new_node_with_optimizer(new_iff);
 227   Node *if_cont = new IfTrueNode(new_iff);
 228   Node *if_uct  = new IfFalseNode(new_iff);
 229   if (cont_proj->is_IfFalse()) {
 230     // Swap
 231     Node* tmp = if_uct; if_uct = if_cont; if_cont = tmp;
 232   }
 233   register_new_node_with_optimizer(if_cont);
 234   register_new_node_with_optimizer(if_uct);
 235 
 236   // if_uct to rgn
 237   hash_delete(rgn);
 238   rgn->add_req(if_uct);
 239 
 240   // If rgn has phis add corresponding new edges which has the same
 241   // value as on original uncommon_proj pass.
 242   assert(rgn->in(rgn->req() -1) == if_uct, "new edge should be last");
 243   bool has_phi = false;
 244   for (DUIterator_Fast imax, i = rgn->fast_outs(imax); i < imax; i++) {
 245     Node* use = rgn->fast_out(i);
 246     if (use->is_Phi() && use->outcnt() > 0) {
 247       rehash_node_delayed(use);
 248       use->add_req(use->in(proj_index));
 249       has_phi = true;
 250     }
 251   }
 252   assert(!has_phi || rgn->req() > 3, "no phis when region is created");
 253 
 254   return if_cont->as_Proj();
 255 }
 256 
 257 //--------------------------clone_predicate-----------------------
 258 ProjNode* PhaseIdealLoop::clone_predicate(ProjNode* predicate_proj, Node* new_entry,
 259                                           Deoptimization::DeoptReason reason,
 260                                           PhaseIdealLoop* loop_phase,
 261                                           PhaseIterGVN* igvn) {
 262   ProjNode* new_predicate_proj;
 263   if (loop_phase != NULL) {
 264     new_predicate_proj = loop_phase->create_new_if_for_predicate(predicate_proj, new_entry, reason, Op_If);
 265   } else {
 266     new_predicate_proj =       igvn->create_new_if_for_predicate(predicate_proj, new_entry, reason, Op_If);
 267   }
 268   IfNode* iff = new_predicate_proj->in(0)->as_If();
 269   Node* ctrl  = iff->in(0);
 270 
 271   // Match original condition since predicate's projections could be swapped.
 272   assert(predicate_proj->in(0)->in(1)->in(1)->Opcode()==Op_Opaque1, "must be");
 273   Node* opq = new Opaque1Node(igvn->C, predicate_proj->in(0)->in(1)->in(1)->in(1));
 274   igvn->C->add_predicate_opaq(opq);
 275 
 276   Node* bol = new Conv2BNode(opq);
 277   if (loop_phase != NULL) {
 278     loop_phase->register_new_node(opq, ctrl);
 279     loop_phase->register_new_node(bol, ctrl);
 280   } else {
 281     igvn->register_new_node_with_optimizer(opq);
 282     igvn->register_new_node_with_optimizer(bol);
 283   }
 284   igvn->hash_delete(iff);
 285   iff->set_req(1, bol);
 286   return new_predicate_proj;


 709       tty->print("missing predicate:");
 710       loop->dump_head();
 711       head->dump(1);
 712     }
 713 #endif
 714     return false;
 715   }
 716   ConNode* zero = _igvn.intcon(0);
 717   set_ctrl(zero, C->root());
 718 
 719   ResourceArea *area = Thread::current()->resource_area();
 720   Invariance invar(area, loop);
 721 
 722   // Create list of if-projs such that a newer proj dominates all older
 723   // projs in the list, and they all dominate loop->tail()
 724   Node_List if_proj_list(area);
 725   Node *current_proj = loop->tail(); //start from tail
 726   while (current_proj != head) {
 727     if (loop == get_loop(current_proj) && // still in the loop ?
 728         current_proj->is_Proj()        && // is a projection  ?
 729         (current_proj->in(0)->Opcode() == Op_If ||
 730          current_proj->in(0)->Opcode() == Op_RangeCheck)) { // is a if projection ?
 731       if_proj_list.push(current_proj);
 732     }
 733     current_proj = idom(current_proj);
 734   }
 735 
 736   bool hoisted = false; // true if at least one proj is promoted
 737   while (if_proj_list.size() > 0) {
 738     // Following are changed to nonnull when a predicate can be hoisted
 739     ProjNode* new_predicate_proj = NULL;
 740 
 741     ProjNode* proj = if_proj_list.pop()->as_Proj();
 742     IfNode*   iff  = proj->in(0)->as_If();
 743 
 744     if (!proj->is_uncommon_trap_if_pattern(Deoptimization::Reason_none)) {
 745       if (loop->is_loop_exit(iff)) {
 746         // stop processing the remaining projs in the list because the execution of them
 747         // depends on the condition of "iff" (iff->in(1)).
 748         break;
 749       } else {
 750         // Both arms are inside the loop. There are two cases:
 751         // (1) there is one backward branch. In this case, any remaining proj
 752         //     in the if_proj list post-dominates "iff". So, the condition of "iff"
 753         //     does not determine the execution the remining projs directly, and we
 754         //     can safely continue.
 755         // (2) both arms are forwarded, i.e. a diamond shape. In this case, "proj"
 756         //     does not dominate loop->tail(), so it can not be in the if_proj list.
 757         continue;
 758       }
 759     }
 760 
 761     Node*     test = iff->in(1);
 762     if (!test->is_Bool()){ //Conv2B, ...
 763       continue;
 764     }
 765     BoolNode* bol = test->as_Bool();
 766     if (invar.is_invariant(bol)) {
 767       // Invariant test
 768       new_predicate_proj = create_new_if_for_predicate(predicate_proj, NULL,
 769                                                        Deoptimization::Reason_predicate,
 770                                                        iff->Opcode());
 771       Node* ctrl = new_predicate_proj->in(0)->as_If()->in(0);
 772       BoolNode* new_predicate_bol = invar.clone(bol, ctrl)->as_Bool();
 773 
 774       // Negate test if necessary
 775       bool negated = false;
 776       if (proj->_con != predicate_proj->_con) {
 777         new_predicate_bol = new BoolNode(new_predicate_bol->in(1), new_predicate_bol->_test.negate());
 778         register_new_node(new_predicate_bol, ctrl);
 779         negated = true;
 780       }
 781       IfNode* new_predicate_iff = new_predicate_proj->in(0)->as_If();
 782       _igvn.hash_delete(new_predicate_iff);
 783       new_predicate_iff->set_req(1, new_predicate_bol);
 784 #ifndef PRODUCT
 785       if (TraceLoopPredicate) {
 786         tty->print("Predicate invariant if%s: %d ", negated ? " negated" : "", new_predicate_iff->_idx);
 787         loop->dump_head();
 788       } else if (TraceLoopOpts) {
 789         tty->print("Predicate IC ");
 790         loop->dump_head();


 794       // Range check for counted loops
 795       const Node*    cmp    = bol->in(1)->as_Cmp();
 796       Node*          idx    = cmp->in(1);
 797       assert(!invar.is_invariant(idx), "index is variant");
 798       Node* rng = cmp->in(2);
 799       assert(rng->Opcode() == Op_LoadRange || _igvn.type(rng)->is_int() >= 0, "must be");
 800       assert(invar.is_invariant(rng), "range must be invariant");
 801       int scale    = 1;
 802       Node* offset = zero;
 803       bool ok = is_scaled_iv_plus_offset(idx, cl->phi(), &scale, &offset);
 804       assert(ok, "must be index expression");
 805 
 806       Node* init    = cl->init_trip();
 807       Node* limit   = cl->limit();
 808       Node* stride  = cl->stride();
 809 
 810       // Build if's for the upper and lower bound tests.  The
 811       // lower_bound test will dominate the upper bound test and all
 812       // cloned or created nodes will use the lower bound test as
 813       // their declared control.
 814       ProjNode* lower_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate, iff->Opcode());
 815       ProjNode* upper_bound_proj = create_new_if_for_predicate(predicate_proj, NULL, Deoptimization::Reason_predicate, iff->Opcode());
 816       assert(upper_bound_proj->in(0)->as_If()->in(0) == lower_bound_proj, "should dominate");
 817       Node *ctrl = lower_bound_proj->in(0)->as_If()->in(0);
 818 
 819       // Perform cloning to keep Invariance state correct since the
 820       // late schedule will place invariant things in the loop.
 821       rng = invar.clone(rng, ctrl);
 822       if (offset && offset != zero) {
 823         assert(invar.is_invariant(offset), "offset must be loop invariant");
 824         offset = invar.clone(offset, ctrl);
 825       }
 826 
 827       // Test the lower bound
 828       BoolNode*  lower_bound_bol = rc_predicate(loop, ctrl, scale, offset, init, limit, stride, rng, false);
 829       // Negate test if necessary
 830       bool negated = false;
 831       if (proj->_con != predicate_proj->_con) {
 832         lower_bound_bol = new BoolNode(lower_bound_bol->in(1), lower_bound_bol->_test.negate());
 833         register_new_node(lower_bound_bol, ctrl);
 834         negated = true;
 835       }


src/share/vm/opto/loopPredicate.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File