< prev index next >

src/hotspot/share/opto/loopPredicate.cpp

Print this page




 368 }
 369 
 370 
 371 // Clone loop predicates to cloned loops (peeled, unswitched, split_if).
 372 Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry,
 373                                                 bool clone_limit_check,
 374                                                 PhaseIdealLoop* loop_phase,
 375                                                 PhaseIterGVN* igvn) {
 376 #ifdef ASSERT
 377   if (new_entry == NULL || !(new_entry->is_Proj() || new_entry->is_Region() || new_entry->is_SafePoint())) {
 378     if (new_entry != NULL)
 379       new_entry->dump();
 380     assert(false, "not IfTrue, IfFalse, Region or SafePoint");
 381   }
 382 #endif
 383   // Search original predicates
 384   Node* entry = old_entry;
 385   ProjNode* limit_check_proj = NULL;
 386   limit_check_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
 387   if (limit_check_proj != NULL) {
 388     entry = entry->in(0)->in(0);
 389   }
 390   ProjNode* profile_predicate_proj = NULL;
 391   ProjNode* predicate_proj = NULL;
 392   if (UseProfiledLoopPredicate) {
 393     profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
 394     if (profile_predicate_proj != NULL) {
 395       entry = skip_loop_predicates(entry);
 396     }
 397   }
 398   if (UseLoopPredicate) {
 399     predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
 400   }
 401   if (predicate_proj != NULL) { // right pattern that can be used by loop predication
 402     // clone predicate
 403     ProjNode* proj = clone_predicate(predicate_proj, new_entry,
 404                                      Deoptimization::Reason_predicate,
 405                                      loop_phase, igvn);
 406     assert(proj != NULL, "IfTrue or IfFalse after clone predicate");
 407     new_entry = proj;
 408     if (TraceLoopPredicate) {


 450 // Skip related predicates.
 451 Node* PhaseIdealLoop::skip_loop_predicates(Node* entry) {
 452   IfNode* iff = entry->in(0)->as_If();
 453   ProjNode* uncommon_proj = iff->proj_out(1 - entry->as_Proj()->_con);
 454   Node* rgn = uncommon_proj->unique_ctrl_out();
 455   assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
 456   entry = entry->in(0)->in(0);
 457   while (entry != NULL && entry->is_Proj() && entry->in(0)->is_If()) {
 458     uncommon_proj = entry->in(0)->as_If()->proj_out(1 - entry->as_Proj()->_con);
 459     if (uncommon_proj->unique_ctrl_out() != rgn)
 460       break;
 461     entry = entry->in(0)->in(0);
 462   }
 463   return entry;
 464 }
 465 
 466 Node* PhaseIdealLoop::skip_all_loop_predicates(Node* entry) {
 467   Node* predicate = NULL;
 468   predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
 469   if (predicate != NULL) {
 470     entry = entry->in(0)->in(0);
 471   }
 472   if (UseProfiledLoopPredicate) {
 473     predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
 474     if (predicate != NULL) { // right pattern that can be used by loop predication
 475       entry = skip_loop_predicates(entry);
 476     }
 477   }
 478   if (UseLoopPredicate) {
 479     predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
 480     if (predicate != NULL) { // right pattern that can be used by loop predication
 481       entry = skip_loop_predicates(entry);
 482     }
 483   }
 484   return entry;
 485 }
 486 
 487 //--------------------------find_predicate_insertion_point-------------------
 488 // Find a good location to insert a predicate
 489 ProjNode* PhaseIdealLoop::find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason) {
 490   if (start_c == NULL || !start_c->is_Proj())


1337   }
1338 
1339   CountedLoopNode *cl = NULL;
1340   if (head->is_valid_counted_loop()) {
1341     cl = head->as_CountedLoop();
1342     // do nothing for iteration-splitted loops
1343     if (!cl->is_normal_loop()) return false;
1344     // Avoid RCE if Counted loop's test is '!='.
1345     BoolTest::mask bt = cl->loopexit()->test_trip();
1346     if (bt != BoolTest::lt && bt != BoolTest::gt)
1347       cl = NULL;
1348   }
1349 
1350   Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl);
1351   ProjNode *loop_limit_proj = NULL;
1352   ProjNode *predicate_proj = NULL;
1353   ProjNode *profile_predicate_proj = NULL;
1354   // Loop limit check predicate should be near the loop.
1355   loop_limit_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
1356   if (loop_limit_proj != NULL) {
1357     entry = loop_limit_proj->in(0)->in(0);
1358   }
1359   bool has_profile_predicates = false;
1360   profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
1361   if (profile_predicate_proj != NULL) {
1362     Node* n = skip_loop_predicates(entry);
1363     // Check if predicates were already added to the profile predicate
1364     // block
1365     if (n != entry->in(0)->in(0) || n->outcnt() != 1) {
1366       has_profile_predicates = true;
1367     }
1368     entry = n;
1369   }
1370   predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
1371 
1372   float loop_trip_cnt = -1;
1373   bool follow_branches = loop_predication_should_follow_branches(loop, profile_predicate_proj, loop_trip_cnt);
1374   assert(!follow_branches || loop_trip_cnt >= 0, "negative trip count?");
1375 
1376   if (predicate_proj == NULL && !follow_branches) {
1377 #ifndef PRODUCT




 368 }
 369 
 370 
 371 // Clone loop predicates to cloned loops (peeled, unswitched, split_if).
 372 Node* PhaseIdealLoop::clone_loop_predicates(Node* old_entry, Node* new_entry,
 373                                             bool clone_limit_check,
 374                                             PhaseIdealLoop* loop_phase,
 375                                             PhaseIterGVN* igvn) {
 376 #ifdef ASSERT
 377   if (new_entry == NULL || !(new_entry->is_Proj() || new_entry->is_Region() || new_entry->is_SafePoint())) {
 378     if (new_entry != NULL)
 379       new_entry->dump();
 380     assert(false, "not IfTrue, IfFalse, Region or SafePoint");
 381   }
 382 #endif
 383   // Search original predicates
 384   Node* entry = old_entry;
 385   ProjNode* limit_check_proj = NULL;
 386   limit_check_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
 387   if (limit_check_proj != NULL) {
 388     entry = skip_loop_predicates(entry);
 389   }
 390   ProjNode* profile_predicate_proj = NULL;
 391   ProjNode* predicate_proj = NULL;
 392   if (UseProfiledLoopPredicate) {
 393     profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
 394     if (profile_predicate_proj != NULL) {
 395       entry = skip_loop_predicates(entry);
 396     }
 397   }
 398   if (UseLoopPredicate) {
 399     predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
 400   }
 401   if (predicate_proj != NULL) { // right pattern that can be used by loop predication
 402     // clone predicate
 403     ProjNode* proj = clone_predicate(predicate_proj, new_entry,
 404                                      Deoptimization::Reason_predicate,
 405                                      loop_phase, igvn);
 406     assert(proj != NULL, "IfTrue or IfFalse after clone predicate");
 407     new_entry = proj;
 408     if (TraceLoopPredicate) {


 450 // Skip related predicates.
 451 Node* PhaseIdealLoop::skip_loop_predicates(Node* entry) {
 452   IfNode* iff = entry->in(0)->as_If();
 453   ProjNode* uncommon_proj = iff->proj_out(1 - entry->as_Proj()->_con);
 454   Node* rgn = uncommon_proj->unique_ctrl_out();
 455   assert(rgn->is_Region() || rgn->is_Call(), "must be a region or call uct");
 456   entry = entry->in(0)->in(0);
 457   while (entry != NULL && entry->is_Proj() && entry->in(0)->is_If()) {
 458     uncommon_proj = entry->in(0)->as_If()->proj_out(1 - entry->as_Proj()->_con);
 459     if (uncommon_proj->unique_ctrl_out() != rgn)
 460       break;
 461     entry = entry->in(0)->in(0);
 462   }
 463   return entry;
 464 }
 465 
 466 Node* PhaseIdealLoop::skip_all_loop_predicates(Node* entry) {
 467   Node* predicate = NULL;
 468   predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
 469   if (predicate != NULL) {
 470     entry = skip_loop_predicates(entry);
 471   }
 472   if (UseProfiledLoopPredicate) {
 473     predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
 474     if (predicate != NULL) { // right pattern that can be used by loop predication
 475       entry = skip_loop_predicates(entry);
 476     }
 477   }
 478   if (UseLoopPredicate) {
 479     predicate = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
 480     if (predicate != NULL) { // right pattern that can be used by loop predication
 481       entry = skip_loop_predicates(entry);
 482     }
 483   }
 484   return entry;
 485 }
 486 
 487 //--------------------------find_predicate_insertion_point-------------------
 488 // Find a good location to insert a predicate
 489 ProjNode* PhaseIdealLoop::find_predicate_insertion_point(Node* start_c, Deoptimization::DeoptReason reason) {
 490   if (start_c == NULL || !start_c->is_Proj())


1337   }
1338 
1339   CountedLoopNode *cl = NULL;
1340   if (head->is_valid_counted_loop()) {
1341     cl = head->as_CountedLoop();
1342     // do nothing for iteration-splitted loops
1343     if (!cl->is_normal_loop()) return false;
1344     // Avoid RCE if Counted loop's test is '!='.
1345     BoolTest::mask bt = cl->loopexit()->test_trip();
1346     if (bt != BoolTest::lt && bt != BoolTest::gt)
1347       cl = NULL;
1348   }
1349 
1350   Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl);
1351   ProjNode *loop_limit_proj = NULL;
1352   ProjNode *predicate_proj = NULL;
1353   ProjNode *profile_predicate_proj = NULL;
1354   // Loop limit check predicate should be near the loop.
1355   loop_limit_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_loop_limit_check);
1356   if (loop_limit_proj != NULL) {
1357     entry = skip_loop_predicates(loop_limit_proj);
1358   }
1359   bool has_profile_predicates = false;
1360   profile_predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_profile_predicate);
1361   if (profile_predicate_proj != NULL) {
1362     Node* n = skip_loop_predicates(entry);
1363     // Check if predicates were already added to the profile predicate
1364     // block
1365     if (n != entry->in(0)->in(0) || n->outcnt() != 1) {
1366       has_profile_predicates = true;
1367     }
1368     entry = n;
1369   }
1370   predicate_proj = find_predicate_insertion_point(entry, Deoptimization::Reason_predicate);
1371 
1372   float loop_trip_cnt = -1;
1373   bool follow_branches = loop_predication_should_follow_branches(loop, profile_predicate_proj, loop_trip_cnt);
1374   assert(!follow_branches || loop_trip_cnt >= 0, "negative trip count?");
1375 
1376   if (predicate_proj == NULL && !follow_branches) {
1377 #ifndef PRODUCT


< prev index next >