Skip to content

Commit e72f205

Browse files
committed
8373524: C2: no reachable node should have no use
Reviewed-by: chagedorn, mhaessig
1 parent 360777c commit e72f205

File tree

2 files changed

+94
-3
lines changed

2 files changed

+94
-3
lines changed

src/hotspot/share/opto/cfgnode.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,7 +2642,7 @@ Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
26422642
}
26432643
Node* phi = mms.memory();
26442644
assert(made_new_phi || phi->in(i) == n, "replace the i-th merge by a slice");
2645-
phi->set_req(i, mms.memory2());
2645+
phi->set_req_X(i, mms.memory2(), phase);
26462646
}
26472647
}
26482648
}
@@ -2651,7 +2651,9 @@ Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
26512651
for (MergeMemStream mms(result); mms.next_non_empty(); ) {
26522652
Node* phi = mms.memory();
26532653
for (uint i = 1; i < req(); ++i) {
2654-
if (phi->in(i) == this) phi->set_req(i, phi);
2654+
if (phi->in(i) == this) {
2655+
phi->set_req_X(i, phi, phase);
2656+
}
26552657
}
26562658
}
26572659
}
@@ -2673,7 +2675,7 @@ Node *PhiNode::Ideal(PhaseGVN *phase, bool can_reshape) {
26732675
Node *ii = in(i);
26742676
Node *new_in = MemNode::optimize_memory_chain(ii, at, nullptr, phase);
26752677
if (ii != new_in ) {
2676-
set_req(i, new_in);
2678+
set_req_X(i, new_in, phase);
26772679
progress = this;
26782680
}
26792681
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2025 IBM Corporation. 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 8373524
27+
* @summary C2: no reachable node should have no use
28+
* @run main/othervm -Xbatch ${test.main.class}
29+
* @run main ${test.main.class}
30+
*/
31+
32+
package compiler.igvn;
33+
34+
public class TestNodeWithNoUseAfterPhiIdeal {
35+
volatile boolean _mutatorToggle;
36+
37+
boolean _mutatorFlip() {
38+
synchronized (TestNodeWithNoUseAfterPhiIdeal.class) {
39+
_mutatorToggle = new MyBoolean(!_mutatorToggle).v;
40+
return _mutatorToggle;
41+
}
42+
}
43+
44+
class MyBoolean {
45+
boolean v;
46+
MyBoolean(boolean v) {
47+
int N = 32;
48+
for (int i = 0; i < N; i++) {
49+
this.v = v;
50+
}
51+
}
52+
}
53+
54+
int[] arr;
55+
void test() {
56+
int limit = 2;
57+
boolean flag1 = _mutatorFlip();
58+
for (; limit < 4; limit *= 2) {
59+
if (flag1) {
60+
break;
61+
}
62+
}
63+
int zero = 34;
64+
for (int peel = 2; peel < limit; peel++) {
65+
synchronized (TestNodeWithNoUseAfterPhiIdeal.class) {
66+
zero = 0;
67+
}
68+
}
69+
if (zero == 0) {
70+
arr = new int[8];
71+
} else {
72+
int M = 4;
73+
for (int i = 0; i < M; i++) {
74+
boolean flag2 = _mutatorFlip();
75+
boolean flag3 = _mutatorFlip();
76+
if (flag2) {
77+
break;
78+
}
79+
}
80+
}
81+
}
82+
83+
public static void main(String[] args) {
84+
TestNodeWithNoUseAfterPhiIdeal t = new TestNodeWithNoUseAfterPhiIdeal();
85+
for (int i = 0; i < 10_000; i++) {
86+
t.test();
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)