Skip to content

Commit

Permalink
8309119: [17u/11u] Redo JDK-8297951: C2: Create skeleton predicates f…
Browse files Browse the repository at this point in the history
…or all If nodes in loop predication

Reviewed-by: mdoerr
  • Loading branch information
GoeLin committed Jul 14, 2023
1 parent 3cc7858 commit a6ef655
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/hotspot/share/opto/loopPredicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,13 +1381,11 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree *loop, ProjNode*
upper_bound_iff->set_req(1, upper_bound_bol);
if (TraceLoopPredicate) tty->print_cr("upper bound check if: %d ", lower_bound_iff->_idx);

// Fall through into rest of the clean up code which will move
// any dependent nodes onto the upper bound test.
new_predicate_proj = upper_bound_proj;

if (iff->is_RangeCheck()) {
new_predicate_proj = insert_initial_skeleton_predicate(iff, loop, if_success_proj, predicate_proj, upper_bound_proj, scale, offset, init, limit, stride, rng, overflow, reason);
}
// Fall through into rest of the cleanup code which will move any dependent nodes to the skeleton predicates of the
// upper bound test. We always need to create skeleton predicates in order to properly remove dead loops when later
// splitting the predicated loop into (unreachable) sub-loops (i.e. done by unrolling, peeling, pre/main/post etc.).
new_predicate_proj = insert_initial_skeleton_predicate(iff, loop, if_success_proj, predicate_proj, upper_bound_proj, scale,
offset, init, limit, stride, rng, overflow, reason);

#ifndef PRODUCT
if (TraceLoopOpts && !TraceLoopPredicate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2022, 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 8297951
* @summary Test that crashes because we do not emit skeleton predicates for normal If nodes for which a range check
* predicate is created in loop predication.
* @requires vm.debug == true & vm.compiler2.enabled
* @run main/othervm -XX:-TieredCompilation -Xbatch -XX:-RangeCheckElimination -XX:+BailoutToInterpreterForThrows
compiler.loopopts.TestMissingSkeletonPredicateForIfNode
*/
package compiler.loopopts;

public class TestMissingSkeletonPredicateForIfNode {
static int iFld = 2, x;
static short limit = 10;

public static void main(String[] args) throws Exception {
for (int i = 0; i < 5000; i++) {
try {
test(i % 2 == 0, i % 3);
} catch (Exception e) {
// Expected
}
}
}

public static void test(boolean flag, int arg) throws Exception {
int sum = 1;
int[] iArr2 = new int[4];
RuntimeException r = new RuntimeException();

for (int i = 0; i < limit; i+=2) { // Pre/main/post + Unrolled once. This results in the following type for the iv phi i: [2..SHORT_MAX]
x = 5 / sum;
if (Integer.compareUnsigned(i, iArr2.length) < 0) { // (**) Loop predication creates a RC predicate for this check
// After unrolling, we have:
//
// iArr2[i]
// iArr2[i+2]
//
// The type of iArr2[i+2] is [4..SHORT_MAX+2] (we need limit to be short such that we do not have an integer overflow
// which would set the type to int). However, the type of the CastII node for the index i+2 is [0..3] because its size
// is only 4. Since the type of i+2 is outside the range of the CastII node, the CastII node is replaced by top and
// some of the data nodes and memory nodes die. We are left with a broken graph and later assert because of that.
iFld += iArr2[i]; // RangeCheck node is removed because it shares the same bool as the If (**).
sum += iFld;
} else {
// Emits an UCT with -XX:+BailoutToInterpreterForThrows and therefore the If (**) satisfies the condition of being a
// range check if with one of its blocks being an UCT.
throw r;
}
if (i > 50) {
break;
}
}
}
}

3 comments on commit a6ef655

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin
Copy link
Member Author

@GoeLin GoeLin commented on a6ef655 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on a6ef655 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-a6ef655b in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit a6ef655b from the openjdk/jdk17u-dev repository.

The commit being backported was authored by Goetz Lindenmaier on 14 Jul 2023 and was reviewed by Martin Doerr.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev.git backport-GoeLin-a6ef655b:backport-GoeLin-a6ef655b
$ git checkout backport-GoeLin-a6ef655b
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev.git backport-GoeLin-a6ef655b

Please sign in to comment.