Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/hotspot/share/opto/loopTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
}