Skip to content

Commit d61f56a

Browse files
committed
8342287: C2 fails with "assert(is_IfTrue()) failed: invalid node class: IfFalse" due to Template Assertion Predicate with two UCTs
Reviewed-by: kvn, thartmann
1 parent 76ae072 commit d61f56a

File tree

4 files changed

+83
-6
lines changed

4 files changed

+83
-6
lines changed

src/hotspot/share/opto/loopnode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,10 @@ SafePointNode* CountedLoopNode::outer_safepoint() const {
28262826

28272827
Node* CountedLoopNode::skip_assertion_predicates_with_halt() {
28282828
Node* ctrl = in(LoopNode::EntryControl);
2829+
if (ctrl == nullptr) {
2830+
// Dying loop.
2831+
return nullptr;
2832+
}
28292833
if (is_main_loop()) {
28302834
ctrl = skip_strip_mined()->in(LoopNode::EntryControl);
28312835
}

src/hotspot/share/opto/predicates.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,22 @@
3434
// Walk over all Initialized Assertion Predicates and return the entry into the first Initialized Assertion Predicate
3535
// (i.e. not belonging to an Initialized Assertion Predicate anymore)
3636
Node* AssertionPredicatesWithHalt::find_entry(Node* start_proj) {
37+
assert(start_proj != nullptr, "should not be null");
3738
Node* entry = start_proj;
3839
while (AssertionPredicateWithHalt::is_predicate(entry)) {
3940
entry = entry->in(0)->in(0);
4041
}
4142
return entry;
4243
}
4344

45+
// An Assertion Predicate has always a true projection on the success path.
46+
bool may_be_assertion_predicate_if(const Node* node) {
47+
assert(node != nullptr, "should not be null");
48+
return node->is_IfTrue() && RegularPredicate::may_be_predicate_if(node->as_IfProj());
49+
}
50+
4451
bool AssertionPredicateWithHalt::is_predicate(const Node* maybe_success_proj) {
45-
if (maybe_success_proj == nullptr || !maybe_success_proj->is_IfProj() || !maybe_success_proj->in(0)->is_If()) {
52+
if (!may_be_assertion_predicate_if(maybe_success_proj)) {
4653
return false;
4754
}
4855
return has_assertion_predicate_opaque(maybe_success_proj) && has_halt(maybe_success_proj);
@@ -133,7 +140,7 @@ bool RuntimePredicate::is_predicate(Node* node, Deoptimization::DeoptReason deop
133140
// A Template Assertion Predicate has an If/RangeCheckNode and either an UCT or a halt node depending on where it
134141
// was created.
135142
bool TemplateAssertionPredicate::is_predicate(Node* node) {
136-
if (!RegularPredicate::may_be_predicate_if(node)) {
143+
if (!may_be_assertion_predicate_if(node)) {
137144
return false;
138145
}
139146
IfNode* if_node = node->in(0)->as_If();

src/hotspot/share/opto/predicates.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,15 @@ class PredicateIterator : public StackObj {
687687
Node* current = _start_node;
688688
PredicateBlockIterator loop_limit_check_predicate_iterator(current, Deoptimization::Reason_loop_limit_check);
689689
current = loop_limit_check_predicate_iterator.for_each(predicate_visitor);
690-
PredicateBlockIterator profiled_loop_predicate_iterator(current, Deoptimization::Reason_profile_predicate);
691-
current = profiled_loop_predicate_iterator.for_each(predicate_visitor);
692-
PredicateBlockIterator loop_predicate_iterator(current, Deoptimization::Reason_predicate);
693-
return loop_predicate_iterator.for_each(predicate_visitor);
690+
if (UseLoopPredicate) {
691+
if (UseProfiledLoopPredicate) {
692+
PredicateBlockIterator profiled_loop_predicate_iterator(current, Deoptimization::Reason_profile_predicate);
693+
current = profiled_loop_predicate_iterator.for_each(predicate_visitor);
694+
}
695+
PredicateBlockIterator loop_predicate_iterator(current, Deoptimization::Reason_predicate);
696+
current = loop_predicate_iterator.for_each(predicate_visitor);
697+
}
698+
return current;
694699
}
695700
};
696701

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
/*
26+
* @test
27+
* @bug 8342287
28+
* @summary Test that a fail path projection of a Template Assertion Predicate is not treated as success path projection
29+
* @run main/othervm -XX:-TieredCompilation -Xbatch
30+
* -XX:CompileCommand=compileonly,compiler.predicates.TestTemplateAssertionPredicateWithTwoUCTs::test
31+
* compiler.predicates.TestTemplateAssertionPredicateWithTwoUCTs
32+
*/
33+
34+
package compiler.predicates;
35+
36+
public class TestTemplateAssertionPredicateWithTwoUCTs {
37+
static int iFld;
38+
39+
public static void main(String[] strArr) {
40+
for (int i = 0; i < 1000; i++) {
41+
test();
42+
}
43+
}
44+
45+
static void test() {
46+
int lArr[][] = new int[100][1];
47+
for (int i14 = 5; i14 < 273; ++i14) {
48+
int i16 = 1;
49+
while (++i16 < 94) {
50+
lArr[i16][0] += 1;
51+
switch (i14) {
52+
case 11:
53+
case 2:
54+
case 13:
55+
iFld = 34;
56+
}
57+
}
58+
}
59+
}
60+
}
61+

0 commit comments

Comments
 (0)