@@ -574,18 +574,23 @@ bool ConnectionGraph::can_reduce_check_users(Node* n, uint nesting) const {
574574 // CmpP/N used by the If controlling the cast.
575575 if (use->in (0 )->is_IfTrue () || use->in (0 )->is_IfFalse ()) {
576576 Node* iff = use->in (0 )->in (0 );
577- if (iff->Opcode () == Op_If && iff->in (1 )->is_Bool () && iff->in (1 )->in (1 )->is_Cmp ()) {
577+ // We may have Opaque4 node between If and Bool nodes.
578+ // Bail out in such case - we need to preserve Opaque4 for correct
579+ // processing predicates after loop opts.
580+ bool can_reduce = (iff->Opcode () == Op_If) && iff->in (1 )->is_Bool () && iff->in (1 )->in (1 )->is_Cmp ();
581+ if (can_reduce) {
578582 Node* iff_cmp = iff->in (1 )->in (1 );
579583 int opc = iff_cmp->Opcode ();
580- if ((opc == Op_CmpP || opc == Op_CmpN) && !can_reduce_cmp (n, iff_cmp)) {
584+ can_reduce = (opc == Op_CmpP || opc == Op_CmpN) && can_reduce_cmp (n, iff_cmp);
585+ }
586+ if (!can_reduce) {
581587#ifndef PRODUCT
582- if (TraceReduceAllocationMerges) {
583- tty->print_cr (" Can NOT reduce Phi %d on invocation %d. CastPP %d doesn't have simple control." , n->_idx , _invocation, use->_idx );
584- n->dump (5 );
585- }
586- #endif
587- return false ;
588+ if (TraceReduceAllocationMerges) {
589+ tty->print_cr (" Can NOT reduce Phi %d on invocation %d. CastPP %d doesn't have simple control." , n->_idx , _invocation, use->_idx );
590+ n->dump (5 );
588591 }
592+ #endif
593+ return false ;
589594 }
590595 }
591596 }
@@ -651,7 +656,12 @@ Node* ConnectionGraph::specialize_cmp(Node* base, Node* curr_ctrl) {
651656 if (curr_ctrl == nullptr || curr_ctrl->is_Region ()) {
652657 con = _igvn->zerocon (t->basic_type ());
653658 } else {
654- Node* curr_cmp = curr_ctrl->in (0 )->in (1 )->in (1 ); // true/false -> if -> bool -> cmp
659+ // can_reduce_check_users() verified graph: true/false -> if -> bool -> cmp
660+ assert (curr_ctrl->in (0 )->Opcode () == Op_If, " unexpected node %s" , curr_ctrl->in (0 )->Name ());
661+ Node* bol = curr_ctrl->in (0 )->in (1 );
662+ assert (bol->is_Bool (), " unexpected node %s" , bol->Name ());
663+ Node* curr_cmp = bol->in (1 );
664+ assert (curr_cmp->Opcode () == Op_CmpP || curr_cmp->Opcode () == Op_CmpN, " unexpected node %s" , curr_cmp->Name ());
655665 con = curr_cmp->in (1 )->is_Con () ? curr_cmp->in (1 ) : curr_cmp->in (2 );
656666 }
657667
0 commit comments