Search in sources :

Example 1 with CompareNode

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

the class CountedLoopInfo method createOverFlowGuard.

@SuppressWarnings("try")
public GuardingNode createOverFlowGuard() {
    GuardingNode overflowGuard = getOverFlowGuard();
    if (overflowGuard != null) {
        return overflowGuard;
    }
    try (DebugCloseable position = loop.loopBegin().withNodeSourcePosition()) {
        IntegerStamp stamp = (IntegerStamp) iv.valueNode().stamp(NodeView.DEFAULT);
        StructuredGraph graph = iv.valueNode().graph();
        // we use a negated guard with a < condition to achieve a >=
        CompareNode cond;
        ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
        if (iv.direction() == Direction.Up) {
            ValueNode v1 = sub(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.maxValue(stamp.getBits()), graph), sub(graph, iv.strideNode(), one));
            if (oneOff) {
                v1 = sub(graph, v1, one);
            }
            cond = graph.unique(new IntegerLessThanNode(v1, end));
        } else {
            assert iv.direction() == Direction.Down;
            ValueNode v1 = add(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.minValue(stamp.getBits()), graph), sub(graph, one, iv.strideNode()));
            if (oneOff) {
                v1 = add(graph, v1, one);
            }
            cond = graph.unique(new IntegerLessThanNode(end, v1));
        }
        assert graph.getGuardsStage().allowsFloatingGuards();
        overflowGuard = graph.unique(new GuardNode(cond, AbstractBeginNode.prevBegin(loop.entryPoint()), DeoptimizationReason.LoopLimitCheck, DeoptimizationAction.InvalidateRecompile, true, // TODO gd: use speculation
        JavaConstant.NULL_POINTER));
        loop.loopBegin().setOverflowGuard(overflowGuard);
        return overflowGuard;
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 2 with CompareNode

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

the class LoopTransformations method updateMainLoopLimit.

private static void updateMainLoopLimit(IfNode preLimit, InductionVariable preIv, LoopFragmentWhole mainLoop) {
    // Update the main loops limit test to be different than the post loop
    StructuredGraph graph = preLimit.graph();
    IfNode mainLimit = mainLoop.getDuplicatedNode(preLimit);
    LogicNode ifTest = mainLimit.condition();
    CompareNode compareNode = (CompareNode) ifTest;
    ValueNode prePhi = preIv.valueNode();
    ValueNode mainPhi = mainLoop.getDuplicatedNode(prePhi);
    ValueNode preStride = preIv.strideNode();
    ValueNode mainStride;
    if (preStride instanceof ConstantNode) {
        mainStride = preStride;
    } else {
        mainStride = mainLoop.getDuplicatedNode(preStride);
    }
    // Fetch the bounds to pose lowering the range by one
    ValueNode ub = null;
    if (compareNode.getX() == mainPhi) {
        ub = compareNode.getY();
    } else if (compareNode.getY() == mainPhi) {
        ub = compareNode.getX();
    } else {
        throw GraalError.shouldNotReachHere();
    }
    // Preloop always performs at least one iteration, so remove that from the main loop.
    ValueNode newLimit = sub(graph, ub, mainStride);
    // Re-wire the condition with the new limit
    compareNode.replaceFirstInput(ub, newLimit);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) IfNode(org.graalvm.compiler.nodes.IfNode)

Example 3 with CompareNode

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

the class LoopTransformations method isUnrollableLoop.

public static boolean isUnrollableLoop(LoopEx loop) {
    if (!loop.isCounted() || !loop.counted().getCounter().isConstantStride() || !loop.loop().getChildren().isEmpty()) {
        return false;
    }
    LoopBeginNode loopBegin = loop.loopBegin();
    LogicNode condition = loop.counted().getLimitTest().condition();
    if (!(condition instanceof CompareNode)) {
        return false;
    }
    if (((CompareNode) condition).condition() == CanonicalCondition.EQ) {
        condition.getDebug().log(DebugContext.VERBOSE_LEVEL, "isUnrollableLoop %s condition unsupported %s ", loopBegin, ((CompareNode) condition).condition());
        return false;
    }
    if (loopBegin.isMainLoop() || loopBegin.isSimpleLoop()) {
        // as well.
        if (loop.loop().getBlocks().size() < 3) {
            return true;
        }
        condition.getDebug().log(DebugContext.VERBOSE_LEVEL, "isUnrollableLoop %s too large to unroll %s ", loopBegin, loop.loop().getBlocks().size());
    }
    return false;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 4 with CompareNode

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

the class SPARCIntegerCompareCanonicalizationPhase method run.

@Override
protected void run(StructuredGraph graph) {
    for (Node n : graph.getNodes()) {
        if (n instanceof CompareNode) {
            CompareNode enode = (CompareNode) n;
            min32(enode, enode.getX());
            min32(enode, enode.getY());
        }
    }
}
Also used : CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) Node(org.graalvm.compiler.graph.Node)

Example 5 with CompareNode

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

the class SPARCNodeMatchRules method ifCompareLogicCas.

@MatchRule("(If (ObjectEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (PointerEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (FloatEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (IntegerEquals=compare value LogicCompareAndSwap=cas))")
public ComplexMatchResult ifCompareLogicCas(IfNode root, CompareNode compare, ValueNode value, LogicCompareAndSwapNode cas) {
    JavaConstant constant = value.asJavaConstant();
    assert compare.condition() == CanonicalCondition.EQ;
    if (constant != null && cas.usages().count() == 1) {
        long constantValue = constant.asLong();
        boolean successIsTrue;
        if (constantValue == 0) {
            successIsTrue = false;
        } else if (constantValue == 1) {
            successIsTrue = true;
        } else {
            return null;
        }
        return builder -> {
            LIRKind kind = getLirKind(cas);
            LabelRef trueLabel = getLIRBlock(root.trueSuccessor());
            LabelRef falseLabel = getLIRBlock(root.falseSuccessor());
            double trueLabelProbability = root.probability(root.trueSuccessor());
            Value expectedValue = operand(cas.getExpectedValue());
            Value newValue = operand(cas.getNewValue());
            SPARCAddressValue address = (SPARCAddressValue) operand(cas.getAddress());
            Condition condition = successIsTrue ? Condition.EQ : Condition.NE;
            Value result = getLIRGeneratorTool().emitValueCompareAndSwap(address, expectedValue, newValue);
            getLIRGeneratorTool().emitCompareBranch(kind.getPlatformKind(), result, expectedValue, condition, false, trueLabel, falseLabel, trueLabelProbability);
            return null;
        };
    }
    return null;
}
Also used : CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) XWORD(jdk.vm.ci.sparc.SPARCKind.XWORD) LabelRef(org.graalvm.compiler.lir.LabelRef) SPARCKind(jdk.vm.ci.sparc.SPARCKind) WORD(jdk.vm.ci.sparc.SPARCKind.WORD) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) Condition(org.graalvm.compiler.core.common.calc.Condition) HWORD(jdk.vm.ci.sparc.SPARCKind.HWORD) IfNode(org.graalvm.compiler.nodes.IfNode) LIRKind(org.graalvm.compiler.core.common.LIRKind) LIRLowerableAccess(org.graalvm.compiler.nodes.memory.LIRLowerableAccess) BYTE(jdk.vm.ci.sparc.SPARCKind.BYTE) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) JavaConstant(jdk.vm.ci.meta.JavaConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode) Value(jdk.vm.ci.meta.Value) ComplexMatchResult(org.graalvm.compiler.core.match.ComplexMatchResult) Access(org.graalvm.compiler.nodes.memory.Access) NodeMatchRules(org.graalvm.compiler.core.gen.NodeMatchRules) GraalError(org.graalvm.compiler.debug.GraalError) LIRGeneratorTool(org.graalvm.compiler.lir.gen.LIRGeneratorTool) SPARCAddressValue(org.graalvm.compiler.lir.sparc.SPARCAddressValue) MatchRule(org.graalvm.compiler.core.match.MatchRule) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) Condition(org.graalvm.compiler.core.common.calc.Condition) CanonicalCondition(org.graalvm.compiler.core.common.calc.CanonicalCondition) Value(jdk.vm.ci.meta.Value) SPARCAddressValue(org.graalvm.compiler.lir.sparc.SPARCAddressValue) JavaConstant(jdk.vm.ci.meta.JavaConstant) SPARCAddressValue(org.graalvm.compiler.lir.sparc.SPARCAddressValue) LIRKind(org.graalvm.compiler.core.common.LIRKind) LabelRef(org.graalvm.compiler.lir.LabelRef) MatchRule(org.graalvm.compiler.core.match.MatchRule)

Aggregations

CompareNode (org.graalvm.compiler.nodes.calc.CompareNode)13 ValueNode (org.graalvm.compiler.nodes.ValueNode)10 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 LogicNode (org.graalvm.compiler.nodes.LogicNode)5 IntegerLessThanNode (org.graalvm.compiler.nodes.calc.IntegerLessThanNode)5 IfNode (org.graalvm.compiler.nodes.IfNode)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)3 Value (jdk.vm.ci.meta.Value)3 LIRKind (org.graalvm.compiler.core.common.LIRKind)3 Condition (org.graalvm.compiler.core.common.calc.Condition)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 ArrayList (java.util.ArrayList)2 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)2 PlatformKind (jdk.vm.ci.meta.PlatformKind)2 Node (org.graalvm.compiler.graph.Node)2 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)2 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)2 IntegerBelowNode (org.graalvm.compiler.nodes.calc.IntegerBelowNode)2 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)2