Skip to content

Commit fadc4b1

Browse files
committedMar 14, 2024
8327423: C2 remove_main_post_loops: check if main-loop belongs to pre-loop, not just assert
Reviewed-by: kvn, chagedorn, roland
1 parent cff0747 commit fadc4b1

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed
 

‎src/hotspot/share/opto/loopTransform.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -3260,7 +3260,6 @@ void IdealLoopTree::adjust_loop_exit_prob(PhaseIdealLoop *phase) {
32603260
}
32613261
}
32623262

3263-
#ifdef ASSERT
32643263
static CountedLoopNode* locate_pre_from_main(CountedLoopNode* main_loop) {
32653264
assert(!main_loop->is_main_no_pre_loop(), "Does not have a pre loop");
32663265
Node* ctrl = main_loop->skip_assertion_predicates_with_halt();
@@ -3273,7 +3272,6 @@ static CountedLoopNode* locate_pre_from_main(CountedLoopNode* main_loop) {
32733272
assert(pre_loop->is_pre_loop(), "No pre loop found");
32743273
return pre_loop;
32753274
}
3276-
#endif
32773275

32783276
// Remove the main and post loops and make the pre loop execute all
32793277
// iterations. Useful when the pre loop is found empty.
@@ -3301,7 +3299,11 @@ void IdealLoopTree::remove_main_post_loops(CountedLoopNode *cl, PhaseIdealLoop *
33013299
return;
33023300
}
33033301

3304-
assert(locate_pre_from_main(main_head) == cl, "bad main loop");
3302+
// We found a main-loop after this pre-loop, but they might not belong together.
3303+
if (locate_pre_from_main(main_head) != cl) {
3304+
return;
3305+
}
3306+
33053307
Node* main_iff = main_head->skip_assertion_predicates_with_halt()->in(0);
33063308

33073309
// Remove the Opaque1Node of the pre loop and make it execute all iterations
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8327423
27+
* @summary Test empty loop removal of pre-loop, with different main-loop after it.
28+
* @run main/othervm -Xcomp
29+
* -XX:CompileCommand=compileonly,compiler.loopopts.TestEmptyPreLoopForDifferentMainLoop::test
30+
* compiler.loopopts.TestEmptyPreLoopForDifferentMainLoop
31+
* @run main compiler.loopopts.TestEmptyPreLoopForDifferentMainLoop
32+
*/
33+
34+
package compiler.loopopts;
35+
36+
public class TestEmptyPreLoopForDifferentMainLoop {
37+
static int sink;
38+
39+
public static void main(String args[]) {
40+
test(false);
41+
}
42+
43+
static void test(boolean flag) {
44+
int x = 8;
45+
for (int j = 0; j < 100; j++) {
46+
for (int k = 0; k < 100; k++) {
47+
if (flag) {
48+
x += k;
49+
sink = 42;
50+
}
51+
}
52+
if (flag) {
53+
break;
54+
}
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)
Please sign in to comment.