@@ -381,35 +381,39 @@ bool IdealLoopTree::policy_peeling( PhaseIdealLoop *phase ) const {
381381// If we got the effect of peeling, either by actually peeling or by making
382382// a pre-loop which must execute at least once, we can remove all
383383// loop-invariant dominated tests in the main body.
384- void PhaseIdealLoop::peeled_dom_test_elim ( IdealLoopTree * loop, Node_List &old_new ) {
384+ void PhaseIdealLoop::peeled_dom_test_elim (IdealLoopTree* loop, Node_List& old_new ) {
385385 bool progress = true ;
386- while ( progress ) {
387- progress = false ; // Reset for next iteration
388- Node *prev = loop->_head ->in (LoopNode::LoopBackControl);// loop->tail();
389- Node *test = prev->in (0 );
390- while ( test != loop->_head ) { // Scan till run off top of loop
391-
386+ while (progress) {
387+ progress = false ; // Reset for next iteration
388+ Node* prev = loop->_head ->in (LoopNode::LoopBackControl); // loop->tail();
389+ Node* test = prev->in (0 );
390+ while (test != loop->_head ) { // Scan till run off top of loop
392391 int p_op = prev->Opcode ();
393- if ( (p_op == Op_IfFalse || p_op == Op_IfTrue) &&
394- test->is_If () && // Test?
395- !test->in (1 )->is_Con () && // And not already obvious?
396- // Condition is not a member of this loop?
397- !loop->is_member (get_loop (get_ctrl (test->in (1 ))))){
392+ assert (test != NULL , " test cannot be NULL" );
393+ Node* test_cond = NULL ;
394+ if ((p_op == Op_IfFalse || p_op == Op_IfTrue) && test->is_If ()) {
395+ test_cond = test->in (1 );
396+ }
397+ if (test_cond != NULL && // Test?
398+ !test_cond->is_Con () && // And not already obvious?
399+ // And condition is not a member of this loop?
400+ !loop->is_member (get_loop (get_ctrl (test_cond)))) {
398401 // Walk loop body looking for instances of this test
399- for ( uint i = 0 ; i < loop->_body .size (); i++ ) {
400- Node *n = loop->_body .at (i);
401- if ( n->is_If () && n->in (1 ) == test->in (1 ) /* && n != loop->tail()->in(0)*/ ) {
402+ for (uint i = 0 ; i < loop->_body .size (); i++) {
403+ Node* n = loop->_body .at (i);
404+ // Check against cached test condition because dominated_by()
405+ // replaces the test condition with a constant.
406+ if (n->is_If () && n->in (1 ) == test_cond) {
402407 // IfNode was dominated by version in peeled loop body
403408 progress = true ;
404- dominated_by ( old_new[prev->_idx ], n );
409+ dominated_by (old_new[prev->_idx ], n);
405410 }
406411 }
407412 }
408413 prev = test;
409414 test = idom (test);
410415 } // End of scan tests in loop
411-
412- } // End of while( progress )
416+ } // End of while (progress)
413417}
414418
415419// ------------------------------do_peeling-------------------------------------
0 commit comments