Skip to content

Commit 2a347bc

Browse files
Don't remove Mod[DF]Node that don't have control output
1 parent aff5aa7 commit 2a347bc

File tree

2 files changed

+99
-2
lines changed

2 files changed

+99
-2
lines changed

Diff for: src/hotspot/share/opto/divnode.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,8 @@ Node* ModFNode::Ideal(PhaseGVN* phase, bool can_reshape) {
15181518
PhaseIterGVN* igvn = phase->is_IterGVN();
15191519

15201520
bool result_is_unused = proj_out_or_null(TypeFunc::Parms) == nullptr;
1521-
if (result_is_unused) {
1521+
bool has_control_output = proj_out_or_null(TypeFunc::Control) != nullptr;
1522+
if (result_is_unused && has_control_output) {
15221523
return replace_with_con(igvn, TypeF::make(0.));
15231524
}
15241525

@@ -1569,7 +1570,8 @@ Node* ModDNode::Ideal(PhaseGVN* phase, bool can_reshape) {
15691570
PhaseIterGVN* igvn = phase->is_IterGVN();
15701571

15711572
bool result_is_unused = proj_out_or_null(TypeFunc::Parms) == nullptr;
1572-
if (result_is_unused) {
1573+
bool has_control_output = proj_out_or_null(TypeFunc::Control) != nullptr;
1574+
if (result_is_unused && has_control_output) {
15731575
return replace_with_con(igvn, TypeD::make(0.));
15741576
}
15751577

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (c) 2025, 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+
package compiler.c2.irTests;
24+
25+
import compiler.lib.ir_framework.*;
26+
27+
/*
28+
* @test
29+
* @bug 8353341
30+
* @summary Test that Ideal transformations of Mod[DF]Node are not crashing
31+
* when control proj is absent, and the node is still removed.
32+
* @library /test/lib /
33+
* @run driver compiler.c2.irTests.FPModWithoutControlProj
34+
*/
35+
public class FPModWithoutControlProj {
36+
static int y;
37+
static public boolean flag;
38+
static int iArr[];
39+
40+
public static void main(String[] args) {
41+
TestFramework.runWithFlags("-XX:+StressIGVN");
42+
}
43+
44+
@Run(test = {"testD", "testF"})
45+
public void runMethod() {
46+
testD();
47+
testF();
48+
}
49+
50+
@Test
51+
@IR(failOn = {IRNode.MOD_D, IRNode.MOD_F})
52+
public void testD() {
53+
int x = 243;
54+
double f1 = 119.303D, f2 = 2.637D;
55+
56+
for (int i11 = 0; i11 < 100; i11++) {
57+
if (flag) {
58+
} else if (flag) {
59+
do {
60+
for (f2 = 3; ; f2--) {
61+
if (f2 % 3 == 1) {
62+
x -= y;
63+
}
64+
iArr[1] += 5;
65+
66+
}
67+
} while (f1 < 234);
68+
}
69+
}
70+
71+
}
72+
73+
@Test
74+
@IR(failOn = {IRNode.MOD_D, IRNode.MOD_F})
75+
public void testF() {
76+
int x = 243;
77+
float f1 = 119.303F, f2 = 2.637F;
78+
79+
for (int i11 = 0; i11 < 100; i11++) {
80+
if (flag) {
81+
} else if (flag) {
82+
do {
83+
for (f2 = 3; ; f2--) {
84+
if (f2 % 3 == 1) {
85+
x -= y;
86+
}
87+
iArr[1] += 5;
88+
89+
}
90+
} while (f1 < 234);
91+
}
92+
}
93+
94+
}
95+
}

0 commit comments

Comments
 (0)