From a0687aee60752a0c3cf08af8533072279c0e0e83 Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Wed, 26 Jun 2024 22:21:09 -0700 Subject: [PATCH 1/2] 8335220: C2: Missing check for Opaque4 node in EscapeAnalysis --- src/hotspot/share/opto/escape.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/hotspot/share/opto/escape.cpp b/src/hotspot/share/opto/escape.cpp index 1338bb3c90901..c29dbe6d8db0e 100644 --- a/src/hotspot/share/opto/escape.cpp +++ b/src/hotspot/share/opto/escape.cpp @@ -574,18 +574,20 @@ bool ConnectionGraph::can_reduce_check_users(Node* n, uint nesting) const { // CmpP/N used by the If controlling the cast. if (use->in(0)->is_IfTrue() || use->in(0)->is_IfFalse()) { Node* iff = use->in(0)->in(0); - if (iff->Opcode() == Op_If && iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp()) { + bool can_reduce = (iff->Opcode() == Op_If) && iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp(); + if (can_reduce) { Node* iff_cmp = iff->in(1)->in(1); int opc = iff_cmp->Opcode(); - if ((opc == Op_CmpP || opc == Op_CmpN) && !can_reduce_cmp(n, iff_cmp)) { + can_reduce = (opc == Op_CmpP || opc == Op_CmpN) && can_reduce_cmp(n, iff_cmp); + } + if (!can_reduce) { #ifndef PRODUCT - if (TraceReduceAllocationMerges) { - tty->print_cr("Can NOT reduce Phi %d on invocation %d. CastPP %d doesn't have simple control.", n->_idx, _invocation, use->_idx); - n->dump(5); - } -#endif - return false; + if (TraceReduceAllocationMerges) { + tty->print_cr("Can NOT reduce Phi %d on invocation %d. CastPP %d doesn't have simple control.", n->_idx, _invocation, use->_idx); + n->dump(5); } +#endif + return false; } } } @@ -651,7 +653,12 @@ Node* ConnectionGraph::specialize_cmp(Node* base, Node* curr_ctrl) { if (curr_ctrl == nullptr || curr_ctrl->is_Region()) { con = _igvn->zerocon(t->basic_type()); } else { - Node* curr_cmp = curr_ctrl->in(0)->in(1)->in(1); // true/false -> if -> bool -> cmp + // can_reduce_check_users() verified graph: true/false -> if -> bool -> cmp + assert(curr_ctrl->in(0)->Opcode() == Op_If, "unexpected node %s", curr_ctrl->in(0)->Name()); + Node* bol = curr_ctrl->in(0)->in(1); + assert(bol->is_Bool(), "unexpected node %s", bol->Name()); + Node* curr_cmp = bol->in(1); + assert(curr_cmp->Opcode() == Op_CmpP || curr_cmp->Opcode() == Op_CmpN, "unexpected node %s", curr_cmp->Name()); con = curr_cmp->in(1)->is_Con() ? curr_cmp->in(1) : curr_cmp->in(2); } From c06f6ce0ebc68476629829cc4016a9cefbd1f170 Mon Sep 17 00:00:00 2001 From: Vladimir Kozlov Date: Thu, 27 Jun 2024 07:54:08 -0700 Subject: [PATCH 2/2] Add comment about Opaque4 --- src/hotspot/share/opto/escape.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hotspot/share/opto/escape.cpp b/src/hotspot/share/opto/escape.cpp index c29dbe6d8db0e..2ca722148b61e 100644 --- a/src/hotspot/share/opto/escape.cpp +++ b/src/hotspot/share/opto/escape.cpp @@ -574,6 +574,9 @@ bool ConnectionGraph::can_reduce_check_users(Node* n, uint nesting) const { // CmpP/N used by the If controlling the cast. if (use->in(0)->is_IfTrue() || use->in(0)->is_IfFalse()) { Node* iff = use->in(0)->in(0); + // We may have Opaque4 node between If and Bool nodes. + // Bail out in such case - we need to preserve Opaque4 for correct + // processing predicates after loop opts. bool can_reduce = (iff->Opcode() == Op_If) && iff->in(1)->is_Bool() && iff->in(1)->in(1)->is_Cmp(); if (can_reduce) { Node* iff_cmp = iff->in(1)->in(1);