Skip to content

Commit bb865f9

Browse files
committed
[GR-39650] Floating div nodes: fixes for stamps.
PullRequest: graal/12590
2 parents 5b72b3d + ef38aa9 commit bb865f9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/GuardNode.java

+12
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,16 @@ public NodeSourcePosition getNoDeoptSuccessorPosition() {
183183
public void setNoDeoptSuccessorPosition(NodeSourcePosition noDeoptSuccessorPosition) {
184184
this.noDeoptSuccessorPosition = noDeoptSuccessorPosition;
185185
}
186+
187+
/**
188+
* Determine if the this guard will lead to an unconditional {@link DeoptimizeNode} because its
189+
* condition is a constant.
190+
*/
191+
public boolean willDeoptUnconditionally() {
192+
if (getCondition() instanceof LogicConstantNode) {
193+
LogicConstantNode c = (LogicConstantNode) getCondition();
194+
return c.getValue() == negated;
195+
}
196+
return false;
197+
}
186198
}

compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/calc/FloatingIntegerDivRemNode.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.graalvm.compiler.nodeinfo.InputType;
3737
import org.graalvm.compiler.nodeinfo.NodeInfo;
3838
import org.graalvm.compiler.nodes.GraphState.StageFlag;
39+
import org.graalvm.compiler.nodes.GuardNode;
3940
import org.graalvm.compiler.nodes.NodeView;
4041
import org.graalvm.compiler.nodes.ValueNode;
4142
import org.graalvm.compiler.nodes.extended.GuardedNode;
@@ -121,8 +122,14 @@ private boolean overflowVisibleSideEffect() {
121122

122123
@Override
123124
public boolean verify() {
124-
GraalError.guarantee((!canDivideByZero() && !overflowVisibleSideEffect()) || graph().isAfterStage(StageFlag.FIXED_READS),
125-
"Floating irem must never create an exception or trap");
125+
/*
126+
* Special case unconditionally deopting rem operations: Other optimziations can lead to
127+
* graphs where the rem operation will unconditionally deopt.
128+
*/
129+
boolean guardWillAlwaysDeopt = getGuard() != null && getGuard() instanceof GuardNode && ((GuardNode) getGuard()).willDeoptUnconditionally();
130+
boolean cannotDeopt = (!canDivideByZero() && !overflowVisibleSideEffect());
131+
boolean isAfterStage = graph().isAfterStage(StageFlag.FIXED_READS);
132+
GraalError.guarantee(guardWillAlwaysDeopt || cannotDeopt || isAfterStage, "Floating irem must never create an exception or trap");
126133
return super.verify();
127134
}
128135
}

0 commit comments

Comments
 (0)