8327423: C2 remove_main_post_loops: check if main-loop belongs to pre-loop, not just assert

Reviewed-by: kvn, chagedorn, roland
This commit is contained in:
Emanuel Peter 2024-03-14 07:12:16 +00:00
parent cff0747d7f
commit fadc4b197e
2 changed files with 62 additions and 3 deletions

View File

@ -3260,7 +3260,6 @@ void IdealLoopTree::adjust_loop_exit_prob(PhaseIdealLoop *phase) {
}
}
#ifdef ASSERT
static CountedLoopNode* locate_pre_from_main(CountedLoopNode* main_loop) {
assert(!main_loop->is_main_no_pre_loop(), "Does not have a pre loop");
Node* ctrl = main_loop->skip_assertion_predicates_with_halt();
@ -3273,7 +3272,6 @@ static CountedLoopNode* locate_pre_from_main(CountedLoopNode* main_loop) {
assert(pre_loop->is_pre_loop(), "No pre loop found");
return pre_loop;
}
#endif
// Remove the main and post loops and make the pre loop execute all
// iterations. Useful when the pre loop is found empty.
@ -3301,7 +3299,11 @@ void IdealLoopTree::remove_main_post_loops(CountedLoopNode *cl, PhaseIdealLoop *
return;
}
assert(locate_pre_from_main(main_head) == cl, "bad main loop");
// We found a main-loop after this pre-loop, but they might not belong together.
if (locate_pre_from_main(main_head) != cl) {
return;
}
Node* main_iff = main_head->skip_assertion_predicates_with_halt()->in(0);
// Remove the Opaque1Node of the pre loop and make it execute all iterations

View File

@ -0,0 +1,57 @@
/*
* 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 8327423
* @summary Test empty loop removal of pre-loop, with different main-loop after it.
* @run main/othervm -Xcomp
* -XX:CompileCommand=compileonly,compiler.loopopts.TestEmptyPreLoopForDifferentMainLoop::test
* compiler.loopopts.TestEmptyPreLoopForDifferentMainLoop
* @run main compiler.loopopts.TestEmptyPreLoopForDifferentMainLoop
*/
package compiler.loopopts;
public class TestEmptyPreLoopForDifferentMainLoop {
static int sink;
public static void main(String args[]) {
test(false);
}
static void test(boolean flag) {
int x = 8;
for (int j = 0; j < 100; j++) {
for (int k = 0; k < 100; k++) {
if (flag) {
x += k;
sink = 42;
}
}
if (flag) {
break;
}
}
}
}