Search in sources :

Example 16 with ConditionalNode

use of org.graalvm.compiler.nodes.calc.ConditionalNode in project graal by oracle.

the class IfNode method canonicalizeConditionalCascade.

private ValueNode canonicalizeConditionalCascade(SimplifierTool tool, ValueNode trueValue, ValueNode falseValue) {
    if (trueValue.getStackKind() != falseValue.getStackKind()) {
        return null;
    }
    if (trueValue.getStackKind() != JavaKind.Int && trueValue.getStackKind() != JavaKind.Long) {
        return null;
    }
    if (trueValue.isConstant() && falseValue.isConstant()) {
        return graph().unique(new ConditionalNode(condition(), trueValue, falseValue));
    } else if (!graph().isAfterExpandLogic()) {
        ConditionalNode conditional = null;
        ValueNode constant = null;
        boolean negateCondition;
        if (trueValue instanceof ConditionalNode && falseValue.isConstant()) {
            conditional = (ConditionalNode) trueValue;
            constant = falseValue;
            negateCondition = true;
        } else if (falseValue instanceof ConditionalNode && trueValue.isConstant()) {
            conditional = (ConditionalNode) falseValue;
            constant = trueValue;
            negateCondition = false;
        } else {
            return null;
        }
        boolean negateConditionalCondition = false;
        ValueNode otherValue = null;
        if (constant == conditional.trueValue()) {
            otherValue = conditional.falseValue();
            negateConditionalCondition = false;
        } else if (constant == conditional.falseValue()) {
            otherValue = conditional.trueValue();
            negateConditionalCondition = true;
        }
        if (otherValue != null && otherValue.isConstant()) {
            double shortCutProbability = probability(trueSuccessor());
            LogicNode newCondition = LogicNode.or(condition(), negateCondition, conditional.condition(), negateConditionalCondition, shortCutProbability);
            return graph().unique(new ConditionalNode(newCondition, constant, otherValue));
        } else if (!negateCondition && constant.isJavaConstant() && conditional.trueValue().isJavaConstant() && conditional.falseValue().isJavaConstant()) {
            IntegerLessThanNode lessThan = null;
            IntegerEqualsNode equals = null;
            if (condition() instanceof IntegerLessThanNode && conditional.condition() instanceof IntegerEqualsNode && constant.asJavaConstant().asLong() == -1 && conditional.trueValue().asJavaConstant().asLong() == 0 && conditional.falseValue().asJavaConstant().asLong() == 1) {
                lessThan = (IntegerLessThanNode) condition();
                equals = (IntegerEqualsNode) conditional.condition();
            } else if (condition() instanceof IntegerEqualsNode && conditional.condition() instanceof IntegerLessThanNode && constant.asJavaConstant().asLong() == 0 && conditional.trueValue().asJavaConstant().asLong() == -1 && conditional.falseValue().asJavaConstant().asLong() == 1) {
                lessThan = (IntegerLessThanNode) conditional.condition();
                equals = (IntegerEqualsNode) condition();
            }
            if (lessThan != null) {
                assert equals != null;
                NodeView view = NodeView.from(tool);
                if ((lessThan.getX() == equals.getX() && lessThan.getY() == equals.getY()) || (lessThan.getX() == equals.getY() && lessThan.getY() == equals.getX())) {
                    return graph().unique(new NormalizeCompareNode(lessThan.getX(), lessThan.getY(), conditional.trueValue().stamp(view).getStackKind(), false));
                }
            }
        }
    }
    return null;
}
Also used : ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) NormalizeCompareNode(org.graalvm.compiler.nodes.calc.NormalizeCompareNode)

Aggregations

ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)16 ValueNode (org.graalvm.compiler.nodes.ValueNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)6 IntegerLessThanNode (org.graalvm.compiler.nodes.calc.IntegerLessThanNode)4 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)3 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)3 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)2 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)2 Test (org.junit.Test)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 CanonicalizedCondition (org.graalvm.compiler.core.common.calc.Condition.CanonicalizedCondition)1 FloatConvert (org.graalvm.compiler.core.common.calc.FloatConvert)1