Skip to content

Commit 4413142

Browse files
committed
8268017: C2: assert(phi_type->isa_int() || phi_type->isa_ptr() || phi_type->isa_long()) failed: bad phi type
Reviewed-by: vlivanov, chagedorn, whuang
1 parent 2bfd708 commit 4413142

File tree

5 files changed

+113
-20
lines changed

5 files changed

+113
-20
lines changed

src/hotspot/share/opto/castnode.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ Node* ConstraintCastNode::make_cast(int opcode, Node* c, Node *n, const Type *t,
106106
cast->set_req(0, c);
107107
return cast;
108108
}
109+
case Op_CastFF: {
110+
Node* cast = new CastFFNode(n, t, carry_dependency);
111+
cast->set_req(0, c);
112+
return cast;
113+
}
114+
case Op_CastDD: {
115+
Node* cast = new CastDDNode(n, t, carry_dependency);
116+
cast->set_req(0, c);
117+
return cast;
118+
}
119+
case Op_CastVV: {
120+
Node* cast = new CastVVNode(n, t, carry_dependency);
121+
cast->set_req(0, c);
122+
return cast;
123+
}
109124
case Op_CheckCastPP: return new CheckCastPPNode(c, n, t, carry_dependency);
110125
default:
111126
fatal("Bad opcode %d", opcode);
@@ -557,3 +572,21 @@ Node* CastP2XNode::Identity(PhaseGVN* phase) {
557572
if (in(1)->Opcode() == Op_CastX2P) return in(1)->in(1);
558573
return this;
559574
}
575+
576+
Node* ConstraintCastNode::make_cast_for_type(Node* c, Node* in, const Type* type) {
577+
Node* cast= NULL;
578+
if (type->isa_int()) {
579+
cast = make_cast(Op_CastII, c, in, type, true);
580+
} else if (type->isa_long()) {
581+
cast = make_cast(Op_CastLL, c, in, type, true);
582+
} else if (type->isa_float()) {
583+
cast = make_cast(Op_CastFF, c, in, type, true);
584+
} else if (type->isa_double()) {
585+
cast = make_cast(Op_CastDD, c, in, type, true);
586+
} else if (type->isa_vect()) {
587+
cast = make_cast(Op_CastVV, c, in, type, true);
588+
} else if (type->isa_ptr()) {
589+
cast = make_cast(Op_CastPP, c, in, type, true);
590+
}
591+
return cast;
592+
}

src/hotspot/share/opto/castnode.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class ConstraintCastNode: public TypeNode {
6262
#ifndef PRODUCT
6363
virtual void dump_spec(outputStream *st) const;
6464
#endif
65+
66+
static Node* make_cast_for_type(Node* c, Node* in, const Type* type);
6567
};
6668

6769
//------------------------------CastIINode-------------------------------------

src/hotspot/share/opto/cfgnode.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,15 +1969,10 @@ Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
19691969
// Wait until after parsing for the type information to propagate from the casts.
19701970
assert(can_reshape, "Invalid during parsing");
19711971
const Type* phi_type = bottom_type();
1972-
assert(phi_type->isa_int() || phi_type->isa_ptr() || phi_type->isa_long(), "bad phi type");
19731972
// Add casts to carry the control dependency of the Phi that is
19741973
// going away
19751974
Node* cast = NULL;
1976-
if (phi_type->isa_int()) {
1977-
cast = ConstraintCastNode::make_cast(Op_CastII, r, uin, phi_type, true);
1978-
} else if (phi_type->isa_long()) {
1979-
cast = ConstraintCastNode::make_cast(Op_CastLL, r, uin, phi_type, true);
1980-
} else {
1975+
if (phi_type->isa_ptr()) {
19811976
const Type* uin_type = phase->type(uin);
19821977
if (!phi_type->isa_oopptr() && !uin_type->isa_oopptr()) {
19831978
cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, phi_type, true);
@@ -2008,6 +2003,8 @@ Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
20082003
cast = ConstraintCastNode::make_cast(Op_CastPP, r, uin, phi_type, true);
20092004
}
20102005
}
2006+
} else {
2007+
cast = ConstraintCastNode::make_cast_for_type(r, uin, phi_type);
20112008
}
20122009
assert(cast != NULL, "cast should be set");
20132010
cast = phase->transform(cast);

src/hotspot/share/opto/loopopts.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,22 +1511,9 @@ void PhaseIdealLoop::try_sink_out_of_loop(Node* n) {
15111511
Node* in = x->in(k);
15121512
if (in != NULL && n_loop->is_member(get_loop(get_ctrl(in)))) {
15131513
const Type* in_t = _igvn.type(in);
1514-
if (in_t->isa_int()) {
1515-
cast = new CastIINode(in, in_t, true);
1516-
} else if (in_t->isa_long()) {
1517-
cast = new CastLLNode(in, in_t, true);
1518-
} else if (in_t->isa_ptr()) {
1519-
cast = new CastPPNode(in, in_t, true);
1520-
} else if (in_t->isa_float()) {
1521-
cast = new CastFFNode(in, in_t, true);
1522-
} else if (in_t->isa_double()) {
1523-
cast = new CastDDNode(in, in_t, true);
1524-
} else if (in_t->isa_vect()) {
1525-
cast = new CastVVNode(in, in_t, true);
1526-
}
1514+
cast = ConstraintCastNode::make_cast_for_type(x_ctrl, in, in_t);
15271515
}
15281516
if (cast != NULL) {
1529-
cast->set_req(0, x_ctrl);
15301517
register_new_node(cast, x_ctrl);
15311518
x->replace_edge(in, cast);
15321519
break;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2021, 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 8268017
27+
* @summary C2: assert(phi_type->isa_int() || phi_type->isa_ptr() || phi_type->isa_long()) failed: bad phi type
28+
*
29+
* @run main/othervm -Xcomp -XX:-TieredCompilation -XX:CompileOnly=TestCastFFAtPhi TestCastFFAtPhi
30+
*
31+
*/
32+
33+
public class TestCastFFAtPhi {
34+
static int N = 400;
35+
static double dArrFld[] = new double[N];
36+
static long iMeth_check_sum = 0;
37+
38+
static {
39+
init(dArrFld, 90.71133);
40+
}
41+
42+
float fArrFld[] = new float[N];
43+
44+
public static void main(String[] strArr) {
45+
TestCastFFAtPhi _instance = new TestCastFFAtPhi();
46+
for (int i = 0; i < 10; i++) {
47+
_instance.mainTest();
48+
}
49+
}
50+
51+
void mainTest() {
52+
int i24 = 121110, i28, i30;
53+
float f2 = 2.486F;
54+
55+
for (i28 = 322; i28 > 6; i28--) {
56+
i30 = 1;
57+
do {
58+
i24 = (int) f2;
59+
fArrFld[1] += i30;
60+
switch (((i28 % 4) * 5) + 32) {
61+
case 36:
62+
f2 *= f2;
63+
}
64+
} while (++i30 < 80);
65+
}
66+
System.out.println(i24 + ",");
67+
}
68+
69+
public static void init(double[] a, double seed) {
70+
for (int j = 0; j < a.length; j++) {
71+
a[j] = (j % 2 == 0) ? seed + j : seed - j;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)