Skip to content

Commit ea056fe

Browse files
author
duke
committedJun 5, 2024
Automatic merge of jdk:master into master
2 parents ae0147c + c5c0867 commit ea056fe

File tree

2 files changed

+90
-4
lines changed

2 files changed

+90
-4
lines changed
 

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

+21-4
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,13 @@ bool PhaseIdealLoop::loop_predication_impl_helper(IdealLoopTree* loop, IfProjNod
12121212
// Limit is not exact.
12131213
// Calculate exact limit here.
12141214
// Note, counted loop's test is '<' or '>'.
1215+
#ifdef ASSERT
1216+
const bool exact_trip_count = cl->has_exact_trip_count();
1217+
const uint trip_count = cl->trip_count();
12151218
loop->compute_trip_count(this);
1219+
assert(exact_trip_count == cl->has_exact_trip_count() && trip_count == cl->trip_count(),
1220+
"should have computed trip count on Loop Predication entry");
1221+
#endif
12161222
Node* limit = exact_limit(loop);
12171223
int stride = cl->stride()->get_int();
12181224

@@ -1321,7 +1327,9 @@ IfProjNode* PhaseIdealLoop::add_template_assertion_predicate(IfNode* iff, IdealL
13211327
max_value = new AddINode(opaque_init, max_value);
13221328
register_new_node(max_value, new_proj);
13231329
// init + (current stride - initial stride) is within the loop so narrow its type by leveraging the type of the iv Phi
1324-
max_value = new CastIINode(max_value, loop->_head->as_CountedLoop()->phi()->bottom_type());
1330+
const Type* type_iv = loop->_head->as_CountedLoop()->phi()->bottom_type();
1331+
assert(!type_iv->is_int()->is_con(), "constant indicates one loop iteration for which we bailed out earlier");
1332+
max_value = new CastIINode(max_value, type_iv);
13251333
register_new_node(max_value, parse_predicate_proj);
13261334

13271335
bol = rc_predicate(new_proj, scale, offset, max_value, limit, stride, rng, (stride > 0) != (scale > 0),
@@ -1350,12 +1358,21 @@ bool PhaseIdealLoop::loop_predication_impl(IdealLoopTree* loop) {
13501358
CountedLoopNode *cl = nullptr;
13511359
if (head->is_valid_counted_loop(T_INT)) {
13521360
cl = head->as_CountedLoop();
1353-
// do nothing for iteration-splitted loops
1354-
if (!cl->is_normal_loop()) return false;
1361+
if (!cl->is_normal_loop()) {
1362+
// Do nothing for iteration-splitted loops
1363+
return false;
1364+
}
1365+
loop->compute_trip_count(this);
1366+
if (cl->trip_count() == 1) {
1367+
// Not worth to hoist checks out of a loop that is only run for one iteration since the checks are only going to
1368+
// be executed once anyway.
1369+
return false;
1370+
}
13551371
// Avoid RCE if Counted loop's test is '!='.
13561372
BoolTest::mask bt = cl->loopexit()->test_trip();
1357-
if (bt != BoolTest::lt && bt != BoolTest::gt)
1373+
if (bt != BoolTest::lt && bt != BoolTest::gt) {
13581374
cl = nullptr;
1375+
}
13591376
}
13601377

13611378
Node* entry = head->skip_strip_mined()->in(LoopNode::EntryControl);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 id=Xcomp
26+
* @bug 8333252
27+
* @summary Test that no Template Assertion Predicate is created in Loop Prediction for one iteration loop.
28+
* @run main/othervm -Xcomp -XX:CompileCommand=compileonly,*TestTemplateWithoutOpaqueLoopNodes::test
29+
* compiler.predicates.assertion.TestTemplateWithoutOpaqueLoopNodes
30+
*/
31+
32+
/*
33+
* @test id=Xbatch
34+
* @bug 8333252
35+
* @summary Test that no Template Assertion Predicate is created in Loop Prediction for one iteration loop.
36+
* @run main/othervm -Xbatch -XX:CompileCommand=compileonly,*TestTemplateWithoutOpaqueLoopNodes::test
37+
* compiler.predicates.assertion.TestTemplateWithoutOpaqueLoopNodes
38+
*/
39+
40+
package compiler.predicates.assertion;
41+
42+
public class TestTemplateWithoutOpaqueLoopNodes {
43+
static long lFld;
44+
static long lArr[] = new long[10];
45+
46+
public static void main(String[] args) {
47+
for (int i = 0; i < 10; i++) {
48+
test();
49+
}
50+
}
51+
52+
static void test() {
53+
int i16 = 1, i17, i19, i20 = 1, i22;
54+
for (i17 = 6; i17 < 7; i17++) {
55+
switch ((i16 >> 1) + 38) {
56+
case 38:
57+
for (i19 = 1; i19 < 200000; i19++) {
58+
}
59+
case 1:
60+
for (i22 = 1; i22 < 2; i22 += 2) {
61+
lArr[i22] = i20;
62+
}
63+
break;
64+
case 4:
65+
lFld = 42;
66+
}
67+
}
68+
}
69+
}

0 commit comments

Comments
 (0)
Please sign in to comment.