package org.graalvm.compiler.replacements.nodes.arithmetic;
import org.graalvm.compiler.core.common.type.IntegerStamp;
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.spi.SimplifierTool;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.AbstractBeginNode;
import org.graalvm.compiler.nodes.NodeView;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.calc.SubNode;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
import jdk.vm.ci.meta.Value;
@NodeInfo
public final class IntegerSubExactSplitNode extends IntegerExactArithmeticSplitNode {
public static final NodeClass<IntegerSubExactSplitNode> TYPE = NodeClass.create(IntegerSubExactSplitNode.class);
public IntegerSubExactSplitNode(Stamp stamp, ValueNode x, ValueNode y, AbstractBeginNode next, AbstractBeginNode overflowSuccessor) {
super(TYPE, stamp, x, y, next, overflowSuccessor);
}
@Override
protected Value generateArithmetic(NodeLIRBuilderTool gen) {
return gen.getLIRGeneratorTool().getArithmetic().emitSub(gen.operand(getX()), gen.operand(getY()), true);
}
@Override
public void simplify(SimplifierTool tool) {
NodeView view = NodeView.from(tool);
if (!IntegerStamp.subtractionCanOverflow((IntegerStamp) x.stamp(view), (IntegerStamp) y.stamp(view))) {
tool.deleteBranch(overflowSuccessor);
tool.addToWorkList(next);
SubNode replacement = graph().unique(new SubNode(x, y));
graph().replaceSplitWithFloating(this, replacement, next);
tool.addToWorkList(replacement);
}
}
}