Search in sources :

Example 31 with IntegerStamp

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

the class ReinterpretStampDoubleToLongTest method run.

@Test
public void run() {
    ParameterNode param = new ParameterNode(0, StampPair.createSingle(inputStamp));
    ValueNode reinterpret = ReinterpretNode.create(JavaKind.Long, param, NodeView.DEFAULT);
    IntegerStamp resultStamp = (IntegerStamp) reinterpret.stamp(NodeView.DEFAULT);
    Assert.assertEquals(Long.SIZE, resultStamp.getBits());
    for (long result : interestingLongs) {
        double input = Double.longBitsToDouble(result);
        if (inputStamp.contains(input) && !resultStamp.contains(result)) {
            Assert.fail(String.format("value %f (0x%x) is in input stamp, but not in result stamp (%s)", input, result, resultStamp));
        }
    }
}
Also used : ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) Test(org.junit.Test)

Example 32 with IntegerStamp

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

the class ReinterpretStampFloatToIntTest method run.

@Test
public void run() {
    ParameterNode param = new ParameterNode(0, StampPair.createSingle(inputStamp));
    ValueNode reinterpret = ReinterpretNode.create(JavaKind.Int, param, NodeView.DEFAULT);
    reinterpret.inferStamp();
    IntegerStamp resultStamp = (IntegerStamp) reinterpret.stamp(NodeView.DEFAULT);
    Assert.assertEquals(Integer.SIZE, resultStamp.getBits());
    for (int result : interestingInts) {
        float input = Float.intBitsToFloat(result);
        if (inputStamp.contains(input) && !resultStamp.contains(result)) {
            Assert.fail(String.format("value %f (0x%x) is in input stamp, but not in result stamp (%s)", input, result, resultStamp));
        }
    }
}
Also used : ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) Test(org.junit.Test)

Example 33 with IntegerStamp

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

the class IntegerStampTest method narrowingKindConversion.

private static Stamp narrowingKindConversion(IntegerStamp stamp, JavaKind kind) {
    Stamp narrow = IntegerStamp.OPS.getNarrow().foldStamp(stamp.getBits(), kind.getBitCount(), stamp);
    IntegerConvertOp<?> implicitExtend = kind.isUnsigned() ? IntegerStamp.OPS.getZeroExtend() : IntegerStamp.OPS.getSignExtend();
    return implicitExtend.foldStamp(kind.getBitCount(), 32, narrow);
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 34 with IntegerStamp

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

the class IntegerStampTest method testJoinWeirdMasks.

@Test
public void testJoinWeirdMasks() {
    IntegerStamp minusOneOrThree = IntegerStamp.create(32, -1, 3, 0x3, 0xFFFFFFFFL);
    IntegerStamp twoOrThree = IntegerStamp.create(32, 2, 3, 0x2, 0x3);
    IntegerStamp three = IntegerStamp.create(32, 3, 3, 0x3, 0x3);
    assertEquals(three, minusOneOrThree.join(twoOrThree));
    IntegerStamp minusOneOrThreeOrOne = IntegerStamp.create(32, -1, 3, 0x1, 0xFFFFFFFFL);
    assertEquals(three, minusOneOrThreeOrOne.join(twoOrThree));
    IntegerStamp a = IntegerStamp.create(32, 0b101, 0b110, 0b100, 0b111);
    IntegerStamp b = IntegerStamp.create(32, 0b011, 0b110, 0b010, 0b111);
    // This exercises a special case:
    // The new lowest bound is max(0b101, 0b011) = 0b101
    // The new down mask is (0b100 | 0b010) = 0b110
    // Now based on lowest bound and down mask, we know that the new lowest bound is 0b110
    // Just making an or with the new down mask would give however (0b110 | 0b101) = 0b111 and
    // would therefore be wrong.
    // New upper bound is 0b110.
    IntegerStamp result = IntegerStamp.create(32, 0b110, 0b110, 0b110, 0b110);
    assertEquals(result, a.join(b));
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Test(org.junit.Test) GraphTest(org.graalvm.compiler.graph.test.GraphTest)

Example 35 with IntegerStamp

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

the class ConstantNode method forPrimitive.

/**
 * Returns a node for a primitive of a given type.
 */
public static ConstantNode forPrimitive(Stamp stamp, Constant constant) {
    if (stamp instanceof IntegerStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericInteger() && stamp.getStackKind() == primitive.getJavaKind().getStackKind();
        IntegerStamp istamp = (IntegerStamp) stamp;
        return forIntegerBits(istamp.getBits(), primitive);
    } else if (stamp instanceof FloatStamp) {
        PrimitiveConstant primitive = (PrimitiveConstant) constant;
        assert primitive.getJavaKind().isNumericFloat() && stamp.getStackKind() == primitive.getJavaKind();
        return forConstant(primitive, null);
    } else {
        assert !(stamp instanceof AbstractObjectStamp);
        return new ConstantNode(constant, stamp.constant(constant, null));
    }
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

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