Search in sources :

Example 1 with FloatDivNode

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;
}
Also used : FloatDivNode(org.graalvm.compiler.nodes.calc.FloatDivNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) NodeView(org.graalvm.compiler.nodes.NodeView)

Aggregations

FloatStamp (org.graalvm.compiler.core.common.type.FloatStamp)1 NodeView (org.graalvm.compiler.nodes.NodeView)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 FloatDivNode (org.graalvm.compiler.nodes.calc.FloatDivNode)1 MulNode (org.graalvm.compiler.nodes.calc.MulNode)1