Search in sources :

Example 61 with IntegerStamp

use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.

the class IntegerSubOverflowsTest method testOverflowCheckStamp07.

@Test
public void testOverflowCheckStamp07() {
    IntegerStamp s1 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
    IntegerStamp s2 = StampFactory.forInteger(8, 1, 1);
    Assert.assertTrue(IntegerStamp.subtractionCanOverflow(s1, s2));
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Test(org.junit.Test)

Example 62 with IntegerStamp

use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.

the class IfNode method checkForUnsignedCompare.

/**
 * Recognize a couple patterns that can be merged into an unsigned compare.
 *
 * @param tool
 * @return true if a replacement was done.
 */
private boolean checkForUnsignedCompare(SimplifierTool tool) {
    assert trueSuccessor().hasNoUsages() && falseSuccessor().hasNoUsages();
    if (condition() instanceof IntegerLessThanNode) {
        NodeView view = NodeView.from(tool);
        IntegerLessThanNode lessThan = (IntegerLessThanNode) condition();
        Constant y = lessThan.getY().stamp(view).asConstant();
        if (y instanceof PrimitiveConstant && ((PrimitiveConstant) y).asLong() == 0 && falseSuccessor().next() instanceof IfNode) {
            IfNode ifNode2 = (IfNode) falseSuccessor().next();
            if (ifNode2.condition() instanceof IntegerLessThanNode) {
                IntegerLessThanNode lessThan2 = (IntegerLessThanNode) ifNode2.condition();
                AbstractBeginNode falseSucc = ifNode2.falseSuccessor();
                AbstractBeginNode trueSucc = ifNode2.trueSuccessor();
                IntegerBelowNode below = null;
                /*
                     * Convert x >= 0 && x < positive which is represented as !(x < 0) && x <
                     * <positive> into an unsigned compare.
                     */
                if (lessThan2.getX() == lessThan.getX() && lessThan2.getY().stamp(view) instanceof IntegerStamp && ((IntegerStamp) lessThan2.getY().stamp(view)).isPositive() && sameDestination(trueSuccessor(), ifNode2.falseSuccessor)) {
                    below = graph().unique(new IntegerBelowNode(lessThan2.getX(), lessThan2.getY()));
                    // swap direction
                    AbstractBeginNode tmp = falseSucc;
                    falseSucc = trueSucc;
                    trueSucc = tmp;
                } else if (lessThan2.getY() == lessThan.getX() && sameDestination(trueSuccessor(), ifNode2.trueSuccessor)) {
                    /*
                         * Convert x >= 0 && x <= positive which is represented as !(x < 0) &&
                         * !(<positive> > x), into x <| positive + 1. This can only be done for
                         * constants since there isn't a IntegerBelowEqualThanNode but that doesn't
                         * appear to be interesting.
                         */
                    JavaConstant positive = lessThan2.getX().asJavaConstant();
                    if (positive != null && positive.asLong() > 0 && positive.asLong() < positive.getJavaKind().getMaxValue()) {
                        ConstantNode newLimit = ConstantNode.forIntegerStamp(lessThan2.getX().stamp(view), positive.asLong() + 1, graph());
                        below = graph().unique(new IntegerBelowNode(lessThan.getX(), newLimit));
                    }
                }
                if (below != null) {
                    ifNode2.setTrueSuccessor(null);
                    ifNode2.setFalseSuccessor(null);
                    IfNode newIfNode = graph().add(new IfNode(below, falseSucc, trueSucc, 1 - trueSuccessorProbability));
                    // Remove the < 0 test.
                    tool.deleteBranch(trueSuccessor);
                    graph().removeSplit(this, falseSuccessor);
                    // Replace the second test with the new one.
                    ifNode2.predecessor().replaceFirstSuccessor(ifNode2, newIfNode);
                    ifNode2.safeDelete();
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) Constant(jdk.vm.ci.meta.Constant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 63 with IntegerStamp

use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.

the class IntegerLowerThanNode method getSucceedingStampForX.

private Stamp getSucceedingStampForX(boolean mirror, boolean strict, Stamp xStampGeneric, Stamp yStampGeneric) {
    if (xStampGeneric instanceof IntegerStamp) {
        IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
        if (yStampGeneric instanceof IntegerStamp) {
            IntegerStamp yStamp = (IntegerStamp) yStampGeneric;
            assert yStamp.getBits() == xStamp.getBits();
            Stamp s = getOp().getSucceedingStampForX(xStamp, yStamp, mirror, strict);
            if (s != null) {
                return s;
            }
        }
    }
    return null;
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 64 with IntegerStamp

use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.

the class IntegerTestNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
    NodeView view = NodeView.from(tool);
    if (forX.isConstant() && forY.isConstant()) {
        return LogicConstantNode.forBoolean((forX.asJavaConstant().asLong() & forY.asJavaConstant().asLong()) == 0);
    }
    if (forX.stamp(view) instanceof IntegerStamp && forY.stamp(view) instanceof IntegerStamp) {
        IntegerStamp xStamp = (IntegerStamp) forX.stamp(view);
        IntegerStamp yStamp = (IntegerStamp) forY.stamp(view);
        if ((xStamp.upMask() & yStamp.upMask()) == 0) {
            return LogicConstantNode.tautology();
        } else if ((xStamp.downMask() & yStamp.downMask()) != 0) {
            return LogicConstantNode.contradiction();
        }
    }
    return this;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 65 with IntegerStamp

use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.

the class IntegerTestNode method getSucceedingStamp.

private static Stamp getSucceedingStamp(boolean negated, Stamp xStampGeneric, Stamp otherStampGeneric) {
    if (xStampGeneric instanceof IntegerStamp && otherStampGeneric instanceof IntegerStamp) {
        IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
        IntegerStamp otherStamp = (IntegerStamp) otherStampGeneric;
        if (negated) {
            if (Long.bitCount(otherStamp.upMask()) == 1) {
                long newDownMask = xStamp.downMask() | otherStamp.upMask();
                if (xStamp.downMask() != newDownMask) {
                    return IntegerStamp.stampForMask(xStamp.getBits(), newDownMask, xStamp.upMask()).join(xStamp);
                }
            }
        } else {
            long restrictedUpMask = ((~otherStamp.downMask()) & xStamp.upMask());
            if (xStamp.upMask() != restrictedUpMask) {
                return IntegerStamp.stampForMask(xStamp.getBits(), xStamp.downMask(), restrictedUpMask).join(xStamp);
            }
        }
    }
    return null;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Aggregations

IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)65 Test (org.junit.Test)21 ValueNode (org.graalvm.compiler.nodes.ValueNode)19 Stamp (org.graalvm.compiler.core.common.type.Stamp)13 NodeView (org.graalvm.compiler.nodes.NodeView)8 AddNode (org.graalvm.compiler.nodes.calc.AddNode)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)5 JavaConstant (jdk.vm.ci.meta.JavaConstant)4 Node (org.graalvm.compiler.graph.Node)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)4 ArrayList (java.util.ArrayList)3 Constant (jdk.vm.ci.meta.Constant)3 PrimitiveConstant (jdk.vm.ci.meta.PrimitiveConstant)3 ArithmeticOpTable (org.graalvm.compiler.core.common.type.ArithmeticOpTable)3 GraphTest (org.graalvm.compiler.graph.test.GraphTest)3 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)3 IntegerBelowNode (org.graalvm.compiler.nodes.calc.IntegerBelowNode)3