Skip to content

Commit 87d5da4

Browse files
committed
8328822: C2: "negative trip count?" assert failure in profile predicate code
Backport-of: 2ceeb6c00135310b7bdabacb92d26d81de525240
1 parent 3892078 commit 87d5da4

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

src/hotspot/share/opto/loopPredicate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ bool PhaseIdealLoop::loop_predication_should_follow_branches(IdealLoopTree* loop
11461146
CountedLoopNode* cl = head->as_CountedLoop();
11471147
if (cl->phi() != nullptr) {
11481148
const TypeInt* t = _igvn.type(cl->phi())->is_int();
1149-
float worst_case_trip_cnt = ((float)t->_hi - t->_lo) / ABS(cl->stride_con());
1149+
float worst_case_trip_cnt = ((float)t->_hi - t->_lo) / ABS((float)cl->stride_con());
11501150
if (worst_case_trip_cnt < loop_trip_cnt) {
11511151
loop_trip_cnt = worst_case_trip_cnt;
11521152
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2024, Red Hat, Inc. 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 8328822
27+
* @summary C2: "negative trip count?" assert failure in profile predicate code
28+
* @run main/othervm -XX:-BackgroundCompilation TestCountedLoopMinJintStride
29+
*/
30+
31+
import java.util.Objects;
32+
33+
public class TestCountedLoopMinJintStride {
34+
public static void main(String[] args) {
35+
for (int i = 0; i < 20_000; i++) {
36+
test1(Integer.MAX_VALUE-1, Integer.MAX_VALUE, 0);
37+
testHelper1(100, -1, Integer.MAX_VALUE, 0);
38+
test2(Integer.MAX_VALUE-1, Integer.MAX_VALUE, 0);
39+
testHelper2(100, -1, Integer.MAX_VALUE, 0);
40+
}
41+
}
42+
43+
private static void test1(int stop, int range, int start) {
44+
testHelper1(stop, Integer.MIN_VALUE, range, start);
45+
}
46+
47+
private static void testHelper1(int stop, int stride, int range, int start) {
48+
for (int i = stop; i >= start; i += stride) {
49+
Objects.checkIndex(i, range);
50+
}
51+
}
52+
53+
private static void test2(int stop, int range, int start) {
54+
testHelper1(stop, Integer.MIN_VALUE, range, start);
55+
}
56+
57+
private static void testHelper2(int stop, int stride, int range, int start) {
58+
for (int i = stop; i >= start; i += stride) {
59+
if (i < 0 || i >= range) {
60+
throw new RuntimeException("out of bounds");
61+
}
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)