Skip to content

Commit 7ce630e

Browse files
committed
[GR-56000] Don't allow IntegerExactOverflowNode as condition in ConditionalNode
PullRequest: graal/19919
2 parents 43d4eb6 + b6ea2df commit 7ce630e

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/nodes/IfNode.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -84,6 +84,7 @@
8484
import jdk.graal.compiler.nodes.spi.SimplifierTool;
8585
import jdk.graal.compiler.nodes.spi.SwitchFoldable;
8686
import jdk.graal.compiler.nodes.util.GraphUtil;
87+
import jdk.graal.compiler.replacements.nodes.arithmetic.IntegerExactOverflowNode;
8788
import jdk.vm.ci.code.CodeUtil;
8889
import jdk.vm.ci.meta.Constant;
8990
import jdk.vm.ci.meta.JavaConstant;
@@ -1706,6 +1707,13 @@ private ValueNode canonicalizeConditionalCascade(SimplifierTool tool, ValueNode
17061707
if (trueValue.getStackKind() != JavaKind.Int && trueValue.getStackKind() != JavaKind.Long) {
17071708
return null;
17081709
}
1710+
if (condition() instanceof IntegerExactOverflowNode) {
1711+
/*
1712+
* An exact overflow node is tightly coupled to the if node that uses it. It must not be
1713+
* used as the condition in a conditional node.
1714+
*/
1715+
return null;
1716+
}
17091717
if (isSafeConditionalInput(trueValue, trueSuccessor) && isSafeConditionalInput(falseValue, falseSuccessor)) {
17101718
return graph().unique(new ConditionalNode(condition(), trueValue, falseValue));
17111719
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/replacements/nodes/arithmetic/IntegerExactOverflowNode.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -31,9 +31,12 @@
3131
import java.util.List;
3232

3333
import jdk.graal.compiler.core.common.type.Stamp;
34+
import jdk.graal.compiler.graph.Node;
3435
import jdk.graal.compiler.graph.NodeClass;
3536
import jdk.graal.compiler.nodeinfo.NodeInfo;
3637
import jdk.graal.compiler.nodes.AbstractBeginNode;
38+
import jdk.graal.compiler.nodes.FixedGuardNode;
39+
import jdk.graal.compiler.nodes.GuardNode;
3740
import jdk.graal.compiler.nodes.IfNode;
3841
import jdk.graal.compiler.nodes.LogicNode;
3942
import jdk.graal.compiler.nodes.NodeView;
@@ -65,6 +68,14 @@ public ValueNode getY() {
6568
return y;
6669
}
6770

71+
@Override
72+
protected boolean verifyNode() {
73+
for (Node usage : usages()) {
74+
assertTrue(usage instanceof GuardNode || usage instanceof FixedGuardNode || usage instanceof IfNode, "exact overflow node must only be used by guards or ifs, found: %s", usage);
75+
}
76+
return super.verifyNode();
77+
}
78+
6879
/**
6980
* Make sure the overflow detection nodes have the same order of inputs as the exact arithmetic
7081
* nodes.
@@ -119,5 +130,12 @@ public void simplify(SimplifierTool tool) {
119130

120131
coupledNodes.forEach(n -> n.replaceAndDelete(split));
121132
}
133+
if (hasNoUsages()) {
134+
/*
135+
* We don't want GVN during canonicalization to find this node and give it usages again,
136+
* since the canonicalizer would not call this simplify method again.
137+
*/
138+
safeDelete();
139+
}
122140
}
123141
}

0 commit comments

Comments
 (0)