From 0b12480de88dc1d2a8d7ca3aa2597be3df1ebde1 Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Wed, 16 Aug 2023 06:58:23 +0000 Subject: [PATCH] 8314233: C2: assert(assertion_predicate_has_loop_opaque_node(iff)) failed: unexpected Reviewed-by: thartmann, kvn --- src/hotspot/share/opto/loopTransform.cpp | 7 ++- .../TestPeelingFindsUnrelatedOpaque4Node.java | 62 +++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 test/hotspot/jtreg/compiler/predicates/TestPeelingFindsUnrelatedOpaque4Node.java diff --git a/src/hotspot/share/opto/loopTransform.cpp b/src/hotspot/share/opto/loopTransform.cpp index 29b878877e8..270cc16f8c7 100644 --- a/src/hotspot/share/opto/loopTransform.cpp +++ b/src/hotspot/share/opto/loopTransform.cpp @@ -2079,12 +2079,17 @@ void PhaseIdealLoop::initialize_assertion_predicates_for_peeled_loop(const Predi Node* control = outer_loop_head->in(LoopNode::EntryControl); Node* input_proj = control; + const Node* parse_predicate_uncommon_trap = predicate_block->parse_predicate()->uncommon_trap(); Node* next_regular_predicate_proj = predicate_block->skip_parse_predicate(); while (next_regular_predicate_proj->is_IfProj()) { IfNode* iff = next_regular_predicate_proj->in(0)->as_If(); + ProjNode* uncommon_proj = iff->proj_out(1 - next_regular_predicate_proj->as_Proj()->_con); + if (uncommon_proj->unique_ctrl_out() != parse_predicate_uncommon_trap) { + // Does not belong to this Predicate Block anymore. + break; + } if (iff->in(1)->Opcode() == Op_Opaque4) { assert(assertion_predicate_has_loop_opaque_node(iff), "unexpected"); - ProjNode* uncommon_proj = iff->proj_out(1 - next_regular_predicate_proj->as_Proj()->_con); input_proj = clone_assertion_predicate_and_initialize(iff, init, stride, next_regular_predicate_proj, uncommon_proj, control, outer_loop, input_proj); diff --git a/test/hotspot/jtreg/compiler/predicates/TestPeelingFindsUnrelatedOpaque4Node.java b/test/hotspot/jtreg/compiler/predicates/TestPeelingFindsUnrelatedOpaque4Node.java new file mode 100644 index 00000000000..7944271bd8f --- /dev/null +++ b/test/hotspot/jtreg/compiler/predicates/TestPeelingFindsUnrelatedOpaque4Node.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test + * @bug 8314233 + * @requires vm.compiler2.enabled + * @summary Test that loop peeling does not treat unrelated Opaque4 node as Template Assertion Predicate. + * @run main/othervm -Xbatch -XX:LoopMaxUnroll=0 + * -XX:CompileCommand=compileonly,compiler.predicates.TestPeelingFindsUnrelatedOpaque4Node::* + * -XX:CompileCommand=inline,*String::* compiler.predicates.TestPeelingFindsUnrelatedOpaque4Node + */ + +package compiler.predicates; + +public class TestPeelingFindsUnrelatedOpaque4Node { + static int iFld; + static boolean flag; + + public static void main(String[] args) { + for (int i = 0; i < 1000; i++) { + test(); + flag = !flag; + } + } + + static void test() { + String s = flag ? "34323653" : "343423"; + s.contains("343"); + // Inlined and will call StringLatin1.indexOf intrinsics which emits Opaque4 node which will be wrongly + // found as Template Assertion Predicate when trying to initialize them which triggers the assert. + s.contains("3442"); + + for (int i = 0; i < 100; i++) { + if (flag) { // Triggers peeling + return; + } + iFld = 34; + } + } +}