Search in sources :

Example 36 with IntegerStamp

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

the class IntegerStampTest method testMaskBasedNarrowing.

@Test
public void testMaskBasedNarrowing() {
    IntegerStamp stamp = IntegerStamp.create(32, 1, 2, 0x2, 0x3);
    IntegerStamp resultStamp = IntegerStamp.create(32, 2, 2);
    assertEquals(resultStamp, stamp);
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Test(org.junit.Test) GraphTest(org.graalvm.compiler.graph.test.GraphTest)

Example 37 with IntegerStamp

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

the class IntegerStampTest method testEmpty.

@Test
public void testEmpty() {
    IntegerStamp intStamp = StampFactory.forInteger(32);
    IntegerStamp longStamp = StampFactory.forInteger(64);
    Stamp intEmpty = StampFactory.empty(JavaKind.Int);
    Stamp longEmpty = StampFactory.empty(JavaKind.Long);
    assertEquals(intStamp.join(intEmpty), intEmpty);
    assertEquals(intStamp.meet(intEmpty), intStamp);
    assertEquals(longStamp.join(longEmpty), longEmpty);
    assertEquals(longStamp.meet(longEmpty), longStamp);
}
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) Test(org.junit.Test) GraphTest(org.graalvm.compiler.graph.test.GraphTest)

Example 38 with IntegerStamp

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

the class LoopEx method detectCounted.

public boolean detectCounted() {
    LoopBeginNode loopBegin = loopBegin();
    FixedNode next = loopBegin.next();
    while (next instanceof FixedGuardNode || next instanceof ValueAnchorNode || next instanceof FullInfopointNode) {
        next = ((FixedWithNextNode) next).next();
    }
    if (next instanceof IfNode) {
        IfNode ifNode = (IfNode) next;
        boolean negated = false;
        if (!loopBegin.isLoopExit(ifNode.falseSuccessor())) {
            if (!loopBegin.isLoopExit(ifNode.trueSuccessor())) {
                return false;
            }
            negated = true;
        }
        LogicNode ifTest = ifNode.condition();
        if (!(ifTest instanceof IntegerLessThanNode) && !(ifTest instanceof IntegerEqualsNode)) {
            if (ifTest instanceof IntegerBelowNode) {
                ifTest.getDebug().log("Ignored potential Counted loop at %s with |<|", loopBegin);
            }
            return false;
        }
        CompareNode lessThan = (CompareNode) ifTest;
        Condition condition = null;
        InductionVariable iv = null;
        ValueNode limit = null;
        if (isOutsideLoop(lessThan.getX())) {
            iv = getInductionVariables().get(lessThan.getY());
            if (iv != null) {
                condition = lessThan.condition().asCondition().mirror();
                limit = lessThan.getX();
            }
        } else if (isOutsideLoop(lessThan.getY())) {
            iv = getInductionVariables().get(lessThan.getX());
            if (iv != null) {
                condition = lessThan.condition().asCondition();
                limit = lessThan.getY();
            }
        }
        if (condition == null) {
            return false;
        }
        if (negated) {
            condition = condition.negate();
        }
        boolean oneOff = false;
        switch(condition) {
            case EQ:
                return false;
            case NE:
                {
                    if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1) {
                        return false;
                    }
                    IntegerStamp initStamp = (IntegerStamp) iv.initNode().stamp(NodeView.DEFAULT);
                    IntegerStamp limitStamp = (IntegerStamp) limit.stamp(NodeView.DEFAULT);
                    if (iv.direction() == Direction.Up) {
                        if (initStamp.upperBound() > limitStamp.lowerBound()) {
                            return false;
                        }
                    } else if (iv.direction() == Direction.Down) {
                        if (initStamp.lowerBound() < limitStamp.upperBound()) {
                            return false;
                        }
                    } else {
                        return false;
                    }
                    break;
                }
            case LE:
                oneOff = true;
                if (iv.direction() != Direction.Up) {
                    return false;
                }
                break;
            case LT:
                if (iv.direction() != Direction.Up) {
                    return false;
                }
                break;
            case GE:
                oneOff = true;
                if (iv.direction() != Direction.Down) {
                    return false;
                }
                break;
            case GT:
                if (iv.direction() != Direction.Down) {
                    return false;
                }
                break;
            default:
                throw GraalError.shouldNotReachHere();
        }
        counted = new CountedLoopInfo(this, iv, ifNode, limit, oneOff, negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor());
        return true;
    }
    return false;
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode)

Example 39 with IntegerStamp

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

the class LoopEx method findInductionVariables.

/**
 * Collect all the basic induction variables for the loop and the find any induction variables
 * which are derived from the basic ones.
 *
 * @param loop
 * @return a map from node to induction variable
 */
private static EconomicMap<Node, InductionVariable> findInductionVariables(LoopEx loop) {
    EconomicMap<Node, InductionVariable> ivs = EconomicMap.create(Equivalence.IDENTITY);
    Queue<InductionVariable> scanQueue = new LinkedList<>();
    LoopBeginNode loopBegin = loop.loopBegin();
    AbstractEndNode forwardEnd = loopBegin.forwardEnd();
    for (PhiNode phi : loopBegin.valuePhis()) {
        ValueNode backValue = phi.singleBackValueOrThis();
        if (backValue == phi) {
            continue;
        }
        ValueNode stride = addSub(loop, backValue, phi);
        if (stride != null) {
            BasicInductionVariable biv = new BasicInductionVariable(loop, (ValuePhiNode) phi, phi.valueAt(forwardEnd), stride, (BinaryArithmeticNode<?>) backValue);
            ivs.put(phi, biv);
            scanQueue.add(biv);
        }
    }
    while (!scanQueue.isEmpty()) {
        InductionVariable baseIv = scanQueue.remove();
        ValueNode baseIvNode = baseIv.valueNode();
        for (ValueNode op : baseIvNode.usages().filter(ValueNode.class)) {
            if (loop.isOutsideLoop(op)) {
                continue;
            }
            if (op.usages().count() == 1 && op.usages().first() == baseIvNode) {
                /*
                     * This is just the base induction variable increment with no other uses so
                     * don't bother reporting it.
                     */
                continue;
            }
            InductionVariable iv = null;
            ValueNode offset = addSub(loop, op, baseIvNode);
            ValueNode scale;
            if (offset != null) {
                iv = new DerivedOffsetInductionVariable(loop, baseIv, offset, (BinaryArithmeticNode<?>) op);
            } else if (op instanceof NegateNode) {
                iv = new DerivedScaledInductionVariable(loop, baseIv, (NegateNode) op);
            } else if ((scale = mul(loop, op, baseIvNode)) != null) {
                iv = new DerivedScaledInductionVariable(loop, baseIv, scale, op);
            } else {
                boolean isValidConvert = op instanceof PiNode || op instanceof SignExtendNode;
                if (!isValidConvert && op instanceof ZeroExtendNode) {
                    ZeroExtendNode zeroExtendNode = (ZeroExtendNode) op;
                    isValidConvert = zeroExtendNode.isInputAlwaysPositive() || ((IntegerStamp) zeroExtendNode.stamp(NodeView.DEFAULT)).isPositive();
                }
                if (isValidConvert) {
                    iv = new DerivedConvertedInductionVariable(loop, baseIv, op.stamp(NodeView.DEFAULT), op);
                }
            }
            if (iv != null) {
                ivs.put(op, iv);
                scanQueue.offer(iv);
            }
        }
    }
    return ivs;
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) SubNode(org.graalvm.compiler.nodes.calc.SubNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) PiNode(org.graalvm.compiler.nodes.PiNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) LinkedList(java.util.LinkedList) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode)

Example 40 with IntegerStamp

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

the class DefaultJavaLoweringProvider method createArrayIndexAddress.

/**
 * Create a PiNode on the index proving that the index is positive. On some platforms this is
 * important to allow the index to be used as an int in the address mode.
 */
public AddressNode createArrayIndexAddress(StructuredGraph graph, ValueNode array, JavaKind elementKind, ValueNode index, GuardingNode boundsCheck) {
    IntegerStamp indexStamp = StampFactory.forInteger(32, 0, Integer.MAX_VALUE - 1);
    ValueNode positiveIndex = graph.maybeAddOrUnique(PiNode.create(index, indexStamp, boundsCheck != null ? boundsCheck.asNode() : null));
    return createArrayAddress(graph, array, elementKind, positiveIndex);
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode)

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