Search in sources :

Example 51 with IntegerStamp

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

the class StampTool method unsignedCompare.

/**
 * Compute the stamp resulting from the unsigned comparison being true.
 *
 * @return null if it's can't be true or it nothing useful can be encoded.
 */
public static Stamp unsignedCompare(Stamp stamp, Stamp stamp2) {
    IntegerStamp x = (IntegerStamp) stamp;
    IntegerStamp y = (IntegerStamp) stamp2;
    if (x.isUnrestricted() && y.isUnrestricted()) {
        // Don't know anything.
        return null;
    }
    // c <| n, where c is a constant and n is known to be positive.
    if (x.lowerBound() == x.upperBound()) {
        if (y.isPositive()) {
            if (x.lowerBound() == (1 << x.getBits()) - 1) {
                // Constant is MAX_VALUE which must fail.
                return null;
            }
            if (x.lowerBound() <= y.lowerBound()) {
                // Test will fail. Return illegalStamp instead?
                return null;
            }
            // are [c+1..-n.upperBound)].
            return StampFactory.forInteger(x.getBits(), x.lowerBound() + 1, y.upperBound());
        }
        return null;
    }
    // n <| c, where c is a strictly positive constant
    if (y.lowerBound() == y.upperBound() && y.isStrictlyPositive()) {
        // The test proves that n is positive and less than c, [0..c-1]
        return StampFactory.forInteger(y.getBits(), 0, y.lowerBound() - 1);
    }
    return null;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 52 with IntegerStamp

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

the class BasicInductionVariable method direction.

@Override
public Direction direction() {
    Stamp stamp = rawStride.stamp(NodeView.DEFAULT);
    if (stamp instanceof IntegerStamp) {
        IntegerStamp integerStamp = (IntegerStamp) stamp;
        Direction dir = null;
        if (integerStamp.isStrictlyPositive()) {
            dir = Direction.Up;
        } else if (integerStamp.isStrictlyNegative()) {
            dir = Direction.Down;
        }
        if (dir != null) {
            if (op instanceof AddNode) {
                return dir;
            } else {
                assert op instanceof SubNode;
                return dir.opposite();
            }
        }
    }
    return null;
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) SubNode(org.graalvm.compiler.nodes.calc.SubNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 53 with IntegerStamp

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

the class AArch64ReadNode method generate.

@Override
public void generate(NodeLIRBuilderTool gen) {
    AArch64LIRGenerator lirgen = (AArch64LIRGenerator) gen.getLIRGeneratorTool();
    AArch64ArithmeticLIRGenerator arithgen = (AArch64ArithmeticLIRGenerator) lirgen.getArithmetic();
    AArch64Kind readKind = (AArch64Kind) lirgen.getLIRKind(accessStamp).getPlatformKind();
    int resultBits = ((IntegerStamp) stamp(NodeView.DEFAULT)).getBits();
    gen.setResult(this, arithgen.emitExtendMemory(isSigned, readKind, resultBits, (AArch64AddressValue) gen.operand(getAddress()), gen.state(this)));
}
Also used : AArch64ArithmeticLIRGenerator(org.graalvm.compiler.core.aarch64.AArch64ArithmeticLIRGenerator) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) AArch64LIRGenerator(org.graalvm.compiler.core.aarch64.AArch64LIRGenerator) AArch64Kind(jdk.vm.ci.aarch64.AArch64Kind) AArch64AddressValue(org.graalvm.compiler.lir.aarch64.AArch64AddressValue)

Example 54 with IntegerStamp

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

the class IntegerExactFoldTest method testFoldingAfterLowering.

@Test
public void testFoldingAfterLowering() {
    StructuredGraph graph = prepareGraph();
    Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
    assertNotNull("original node must be in the graph", originalNode);
    graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
    CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
    PhaseContext context = new PhaseContext(getProviders());
    new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    IntegerExactArithmeticSplitNode loweredNode = graph.getNodes().filter(IntegerExactArithmeticSplitNode.class).first();
    assertNotNull("the lowered node must be in the graph", loweredNode);
    loweredNode.getX().setStamp(StampFactory.forInteger(bits, lowerBoundA, upperBoundA));
    loweredNode.getY().setStamp(StampFactory.forInteger(bits, lowerBoundB, upperBoundB));
    new CanonicalizerPhase().apply(graph, context);
    ValueNode node = findNode(graph);
    boolean overflowExpected = node instanceof IntegerExactArithmeticSplitNode;
    IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
    operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
Also used : GuardsStage(org.graalvm.compiler.nodes.StructuredGraph.GuardsStage) LoweringTool(org.graalvm.compiler.nodes.spi.LoweringTool) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) RunWith(org.junit.runner.RunWith) Parameters(org.junit.runners.Parameterized.Parameters) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) ArrayList(java.util.ArrayList) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) Parameterized(org.junit.runners.Parameterized) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) NodeView(org.graalvm.compiler.nodes.NodeView) Test(org.junit.Test) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) List(java.util.List) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Node(org.graalvm.compiler.graph.Node) Assert(org.junit.Assert) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ValueNode(org.graalvm.compiler.nodes.ValueNode) IntegerExactArithmeticNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) IntegerExactArithmeticSplitNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) Test(org.junit.Test)

Example 55 with IntegerStamp

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

the class IntegerSubOverflowsTest method testOverflowCheckStamp.

@Test
public void testOverflowCheckStamp() {
    IntegerStamp s1 = StampFactory.forInteger(32, Integer.MIN_VALUE, Integer.MIN_VALUE);
    IntegerStamp s2 = StampFactory.forInteger(32, -1, -1);
    Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Test(org.junit.Test)

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