Search in sources :

Example 71 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class PrimitiveStampBoundaryTest method checkBinaryOperation.

private static void checkBinaryOperation(ArithmeticOpTable.BinaryOp<?> op, Stamp result, Stamp v1stamp, Stamp v2stamp) {
    Stamp folded = op.foldStamp(v1stamp, v2stamp);
    if (v1stamp.isEmpty() || v2stamp.isEmpty()) {
        assertTrue(folded.isEmpty());
        assertTrue(v1stamp.asConstant() != null || v1stamp.isEmpty());
        assertTrue(v2stamp.asConstant() != null || v2stamp.isEmpty());
        return;
    }
    Constant constant = op.foldConstant(v1stamp.asConstant(), v2stamp.asConstant());
    if (constant != null) {
        assertFalse(folded.isEmpty());
        Constant constant2 = folded.asConstant();
        if (constant2 == null && v1stamp instanceof FloatStamp) {
            JavaConstant c = (JavaConstant) constant;
            assertTrue((c.getJavaKind() == JavaKind.Double && Double.isNaN(c.asDouble())) || (c.getJavaKind() == JavaKind.Float && Float.isNaN(c.asFloat())));
        } else {
            assertTrue(constant2 != null, "should constant fold %s %s %s %s", op, v1stamp, v2stamp, folded);
            if (!constant.equals(constant2)) {
                op.foldConstant(v1stamp.asConstant(), v2stamp.asConstant());
                op.foldStamp(v1stamp, v2stamp);
            }
            assertTrue(constant.equals(constant2), "should produce same constant %s %s %s %s %s", op, v1stamp, v2stamp, constant, constant2);
        }
        assertTrue(result.meet(folded).equals(result), "result out of range %s %s %s %s %s %s", op, v1stamp, v2stamp, folded, result, result.meet(folded));
    }
}
Also used : PrimitiveStamp(org.graalvm.compiler.core.common.type.PrimitiveStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 72 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class PrimitiveStampBoundaryTest method checkUnaryOperation.

private static void checkUnaryOperation(ArithmeticOpTable.UnaryOp<?> op, Stamp result, Stamp v1stamp) {
    Stamp folded = op.foldStamp(v1stamp);
    Constant v1constant = v1stamp.asConstant();
    if (v1constant != null) {
        Constant constant = op.foldConstant(v1constant);
        if (constant != null) {
            Constant constant2 = folded.asConstant();
            if (constant2 == null && v1stamp instanceof FloatStamp) {
                JavaConstant c = (JavaConstant) constant;
                assertTrue((c.getJavaKind() == JavaKind.Double && Double.isNaN(c.asDouble())) || (c.getJavaKind() == JavaKind.Float && Float.isNaN(c.asFloat())));
            } else {
                assertTrue(constant2 != null, "should constant fold %s %s %s", op, v1stamp, folded);
                assertTrue(constant.equals(constant2), "should produce same constant %s %s %s %s", op, v1stamp, constant, constant2);
            }
        }
    } else {
        assertTrue(v1stamp.isEmpty() || v1stamp instanceof FloatStamp);
    }
    assertTrue(result.meet(folded).equals(result), "result out of range %s %s %s %s %s", op, v1stamp, folded, result, result.meet(folded));
}
Also used : PrimitiveStamp(org.graalvm.compiler.core.common.type.PrimitiveStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp)

Example 73 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class NegateNodeCanonicalizationTest method testChar.

@Test
public void testChar() {
    char[] a = new char[] { Character.MIN_VALUE, Character.MIN_VALUE + 1, 0, 1, Character.MAX_VALUE - 1, Character.MAX_VALUE };
    for (char i : a) {
        ConstantNode node = ConstantNode.forChar(i, graph);
        JavaConstant expected = JavaConstant.forInt(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 74 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class NegateNodeCanonicalizationTest method testInt.

@Test
public void testInt() {
    int[] a = new int[] { Integer.MIN_VALUE, Integer.MIN_VALUE + 1, -1, 0, 1, Integer.MAX_VALUE - 1, Integer.MAX_VALUE };
    for (int i : a) {
        ConstantNode node = ConstantNode.forInt(i, graph);
        JavaConstant expected = JavaConstant.forInt(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Example 75 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class NegateNodeCanonicalizationTest method testFloat.

@Test
public void testFloat() {
    float[] a = new float[] { Float.MIN_VALUE, Float.MIN_VALUE + 1, -1, 0, 1, Float.MAX_VALUE - 1, Float.MAX_VALUE };
    for (float i : a) {
        ConstantNode node = ConstantNode.forFloat(i, graph);
        JavaConstant expected = JavaConstant.forFloat(-i);
        assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp(NodeView.DEFAULT)).getNeg().foldConstant(node.asConstant()));
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) Test(org.junit.Test)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5