From bcfae7141d81d3515c4d3acfda7a5b9b3d7644d3 Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Thu, 24 Oct 2024 12:54:03 +0200 Subject: [PATCH] 8343137: C2: VerifyLoopOptimizations fails with "Was reachable in only one" --- src/hotspot/share/opto/loopnode.cpp | 4 +- ...tAssertionPredicateDoesntConstantFold.java | 0 .../TestMissingSetCtrlForTrueConstant.java | 58 +++++++++++++++++++ ...tTemplateAssertionPredicateNotRemoved.java | 10 ++-- ...TemplateAssertionPredicateWithTwoUCTs.java | 6 +- 5 files changed, 69 insertions(+), 9 deletions(-) rename test/hotspot/jtreg/compiler/predicates/{ => assertion}/TestAssertionPredicateDoesntConstantFold.java (100%) create mode 100644 test/hotspot/jtreg/compiler/predicates/assertion/TestMissingSetCtrlForTrueConstant.java rename test/hotspot/jtreg/compiler/predicates/{ => assertion}/TestTemplateAssertionPredicateNotRemoved.java (88%) rename test/hotspot/jtreg/compiler/predicates/{ => assertion}/TestTemplateAssertionPredicateWithTwoUCTs.java (90%) diff --git a/src/hotspot/share/opto/loopnode.cpp b/src/hotspot/share/opto/loopnode.cpp index 518b93bbf50a9..e2db179676df8 100644 --- a/src/hotspot/share/opto/loopnode.cpp +++ b/src/hotspot/share/opto/loopnode.cpp @@ -4488,7 +4488,9 @@ void PhaseIdealLoop::eliminate_useless_template_assertion_predicates(Unique_Node OpaqueTemplateAssertionPredicateNode* opaque_node = C->template_assertion_predicate_opaq_node(i - 1)->as_OpaqueTemplateAssertionPredicate(); if (!useful_predicates.member(opaque_node)) { // not in the useful list - _igvn.replace_node(opaque_node, _igvn.intcon(1)); + ConINode* one = _igvn.intcon(1); + set_ctrl(one, C->root()); + _igvn.replace_node(opaque_node, one); } } } diff --git a/test/hotspot/jtreg/compiler/predicates/TestAssertionPredicateDoesntConstantFold.java b/test/hotspot/jtreg/compiler/predicates/assertion/TestAssertionPredicateDoesntConstantFold.java similarity index 100% rename from test/hotspot/jtreg/compiler/predicates/TestAssertionPredicateDoesntConstantFold.java rename to test/hotspot/jtreg/compiler/predicates/assertion/TestAssertionPredicateDoesntConstantFold.java diff --git a/test/hotspot/jtreg/compiler/predicates/assertion/TestMissingSetCtrlForTrueConstant.java b/test/hotspot/jtreg/compiler/predicates/assertion/TestMissingSetCtrlForTrueConstant.java new file mode 100644 index 0000000000000..f2dbccff3269b --- /dev/null +++ b/test/hotspot/jtreg/compiler/predicates/assertion/TestMissingSetCtrlForTrueConstant.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024, 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 8343137 + * @requires vm.debug == true & vm.compiler2.enabled + * @summary Test that set_ctrl() is properly set for true constant when folding useless Template Assertion Predicate. + * @run main/othervm -Xcomp -XX:+VerifyLoopOptimizations + * -XX:CompileCommand=compileonly,compiler.predicates.assertion.TestMissingSetCtrlForTrueConstant::test + * compiler.predicates.assertion.TestMissingSetCtrlForTrueConstant + */ + +package compiler.predicates.assertion; + +public class TestMissingSetCtrlForTrueConstant { + static long iFld; + static int[] iArrFld = new int[100]; + static double[] dArrFld = new double[100]; + + public static void main(String[] strArr) { + test(); + } + + static void test() { + long l = 34; + for (int i = 78; i > 8; --i) { + switch (i) { + case 24: + l += iFld - 34; + case 25: + iFld = iArrFld[i] += i; + } + dArrFld[i + 1] += i; + } + } +} \ No newline at end of file diff --git a/test/hotspot/jtreg/compiler/predicates/TestTemplateAssertionPredicateNotRemoved.java b/test/hotspot/jtreg/compiler/predicates/assertion/TestTemplateAssertionPredicateNotRemoved.java similarity index 88% rename from test/hotspot/jtreg/compiler/predicates/TestTemplateAssertionPredicateNotRemoved.java rename to test/hotspot/jtreg/compiler/predicates/assertion/TestTemplateAssertionPredicateNotRemoved.java index 557d9d461bfad..6d8588213b5d0 100644 --- a/test/hotspot/jtreg/compiler/predicates/TestTemplateAssertionPredicateNotRemoved.java +++ b/test/hotspot/jtreg/compiler/predicates/assertion/TestTemplateAssertionPredicateNotRemoved.java @@ -29,14 +29,14 @@ * completely with JDK-8288981 and 8314116 just mitigates the problem. * @requires vm.compiler2.enabled * @run main/othervm -Xbatch -XX:-TieredCompilation - * -XX:CompileCommand=compileonly,compiler.predicates.TestTemplateAssertionPredicateNotRemoved::* - * compiler.predicates.TestTemplateAssertionPredicateNotRemoved + * -XX:CompileCommand=compileonly,compiler.predicates.assertion.TestTemplateAssertionPredicateNotRemoved::* + * compiler.predicates.assertion.TestTemplateAssertionPredicateNotRemoved * @run main/othervm -Xbatch -XX:-TieredCompilation -XX:LoopMaxUnroll=0 - * -XX:CompileCommand=compileonly,compiler.predicates.TestTemplateAssertionPredicateNotRemoved::* - * compiler.predicates.TestTemplateAssertionPredicateNotRemoved + * -XX:CompileCommand=compileonly,compiler.predicates.assertion.TestTemplateAssertionPredicateNotRemoved::* + * compiler.predicates.assertion.TestTemplateAssertionPredicateNotRemoved */ -package compiler.predicates; +package compiler.predicates.assertion; public class TestTemplateAssertionPredicateNotRemoved { static int[] iArrFld = new int[10]; diff --git a/test/hotspot/jtreg/compiler/predicates/TestTemplateAssertionPredicateWithTwoUCTs.java b/test/hotspot/jtreg/compiler/predicates/assertion/TestTemplateAssertionPredicateWithTwoUCTs.java similarity index 90% rename from test/hotspot/jtreg/compiler/predicates/TestTemplateAssertionPredicateWithTwoUCTs.java rename to test/hotspot/jtreg/compiler/predicates/assertion/TestTemplateAssertionPredicateWithTwoUCTs.java index aadaf75869f2e..7d21f6b5f2dab 100644 --- a/test/hotspot/jtreg/compiler/predicates/TestTemplateAssertionPredicateWithTwoUCTs.java +++ b/test/hotspot/jtreg/compiler/predicates/assertion/TestTemplateAssertionPredicateWithTwoUCTs.java @@ -27,11 +27,11 @@ * @bug 8342287 * @summary Test that a fail path projection of a Template Assertion Predicate is not treated as success path projection. * @run main/othervm -XX:-TieredCompilation -Xbatch - * -XX:CompileCommand=compileonly,compiler.predicates.TestTemplateAssertionPredicateWithTwoUCTs::test - * compiler.predicates.TestTemplateAssertionPredicateWithTwoUCTs + * -XX:CompileCommand=compileonly,compiler.predicates.assertion.TestTemplateAssertionPredicateWithTwoUCTs::test + * compiler.predicates.assertion.TestTemplateAssertionPredicateWithTwoUCTs */ -package compiler.predicates; +package compiler.predicates.assertion; public class TestTemplateAssertionPredicateWithTwoUCTs { static int iFld;