use of org.graalvm.compiler.nodes.calc.FloatDivNode in project graal by oracle.
the class BinaryMathIntrinsicNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
ValueNode c = tryConstantFold(forX, forY, getOperation());
if (c != null) {
return c;
}
if (forY.isConstant()) {
double yValue = forY.asJavaConstant().asDouble();
// If the second argument is positive or negative zero, then the result is 1.0.
if (yValue == 0.0D) {
return ConstantNode.forDouble(1);
}
// If the second argument is 1.0, then the result is the same as the first argument.
if (yValue == 1.0D) {
return x;
}
// If the second argument is NaN, then the result is NaN.
if (Double.isNaN(yValue)) {
return ConstantNode.forDouble(Double.NaN);
}
// x**-1 = 1/x
if (yValue == -1.0D) {
return new FloatDivNode(ConstantNode.forDouble(1), x);
}
// x**2 = x*x
if (yValue == 2.0D) {
return new MulNode(x, x);
}
// x**0.5 = sqrt(x)
if (yValue == 0.5D && x.stamp(view) instanceof FloatStamp && ((FloatStamp) x.stamp(view)).lowerBound() >= 0.0D) {
return SqrtNode.create(x, view);
}
}
return this;
}
Aggregations