@@ -507,24 +507,29 @@ uint IdealLoopTree::estimate_peeling(PhaseIdealLoop *phase) {
507507// If we got the effect of peeling, either by actually peeling or by making
508508// a pre-loop which must execute at least once, we can remove all
509509// loop-invariant dominated tests in the main body.
510- void PhaseIdealLoop::peeled_dom_test_elim (IdealLoopTree * loop, Node_List & old_new) {
510+ void PhaseIdealLoop::peeled_dom_test_elim (IdealLoopTree* loop, Node_List& old_new) {
511511 bool progress = true ;
512512 while (progress) {
513- progress = false ; // Reset for next iteration
514- Node * prev = loop->_head ->in (LoopNode::LoopBackControl);// loop->tail();
515- Node * test = prev->in (0 );
513+ progress = false ; // Reset for next iteration
514+ Node* prev = loop->_head ->in (LoopNode::LoopBackControl); // loop->tail();
515+ Node* test = prev->in (0 );
516516 while (test != loop->_head ) { // Scan till run off top of loop
517-
518517 int p_op = prev->Opcode ();
519- if ((p_op == Op_IfFalse || p_op == Op_IfTrue) &&
520- test->is_If () && // Test?
521- !test->in (1 )->is_Con () && // And not already obvious?
522- // Condition is not a member of this loop?
523- !loop->is_member (get_loop (get_ctrl (test->in (1 ))))){
518+ assert (test != NULL , " test cannot be NULL" );
519+ Node* test_cond = NULL ;
520+ if ((p_op == Op_IfFalse || p_op == Op_IfTrue) && test->is_If ()) {
521+ test_cond = test->in (1 );
522+ }
523+ if (test_cond != NULL && // Test?
524+ !test_cond->is_Con () && // And not already obvious?
525+ // And condition is not a member of this loop?
526+ !loop->is_member (get_loop (get_ctrl (test_cond)))) {
524527 // Walk loop body looking for instances of this test
525528 for (uint i = 0 ; i < loop->_body .size (); i++) {
526- Node *n = loop->_body .at (i);
527- if (n->is_If () && n->in (1 ) == test->in (1 ) /* && n != loop->tail()->in(0)*/ ) {
529+ Node* n = loop->_body .at (i);
530+ // Check against cached test condition because dominated_by()
531+ // replaces the test condition with a constant.
532+ if (n->is_If () && n->in (1 ) == test_cond) {
528533 // IfNode was dominated by version in peeled loop body
529534 progress = true ;
530535 dominated_by (old_new[prev->_idx ], n);
@@ -534,7 +539,6 @@ void PhaseIdealLoop::peeled_dom_test_elim(IdealLoopTree *loop, Node_List &old_ne
534539 prev = test;
535540 test = idom (test);
536541 } // End of scan tests in loop
537-
538542 } // End of while (progress)
539543}
540544
0 commit comments