Search in sources :

Example 1 with IntegerStamp

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

the class AMD64HotSpotAddressLowering method signExtend.

/**
 * Create a sign extend for {@code input}, or zero extend if {@code input} can be proven
 * positive.
 */
private static ValueNode signExtend(ValueNode input, LoopEx loop) {
    StructuredGraph graph = input.graph();
    if (input instanceof PhiNode) {
        EconomicMap<Node, InductionVariable> ivs = loop.getInductionVariables();
        InductionVariable inductionVariable = ivs.get(input);
        if (inductionVariable != null && inductionVariable instanceof BasicInductionVariable) {
            CountedLoopInfo countedLoopInfo = loop.counted();
            IntegerStamp initStamp = (IntegerStamp) inductionVariable.initNode().stamp(NodeView.DEFAULT);
            if (initStamp.isPositive()) {
                if (inductionVariable.isConstantExtremum()) {
                    long init = inductionVariable.constantInit();
                    long stride = inductionVariable.constantStride();
                    long extremum = inductionVariable.constantExtremum();
                    if (init >= 0 && extremum >= 0) {
                        long shortestTrip = (extremum - init) / stride + 1;
                        if (countedLoopInfo.constantMaxTripCount().equals(shortestTrip)) {
                            return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
                        }
                    }
                }
                if (countedLoopInfo.getCounter() == inductionVariable && inductionVariable.direction() == InductionVariable.Direction.Up && countedLoopInfo.getOverFlowGuard() != null) {
                    return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
                }
            }
        }
    }
    return input.graph().maybeAddOrUnique(SignExtendNode.create(input, ADDRESS_BITS, NodeView.DEFAULT));
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) PhiNode(org.graalvm.compiler.nodes.PhiNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GraalHotSpotVMConfigNode(org.graalvm.compiler.hotspot.nodes.GraalHotSpotVMConfigNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) CompressionNode(org.graalvm.compiler.nodes.CompressionNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) PhiNode(org.graalvm.compiler.nodes.PhiNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) CountedLoopInfo(org.graalvm.compiler.loop.CountedLoopInfo) BasicInductionVariable(org.graalvm.compiler.loop.BasicInductionVariable) InductionVariable(org.graalvm.compiler.loop.InductionVariable) DerivedInductionVariable(org.graalvm.compiler.loop.DerivedInductionVariable) BasicInductionVariable(org.graalvm.compiler.loop.BasicInductionVariable) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode)

Example 2 with IntegerStamp

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

the class IntegerSwitchNode method tryRemoveUnreachableKeys.

/**
 * Remove unreachable keys from the switch based on the stamp of the value, i.e., based on the
 * known range of the switch value.
 */
public boolean tryRemoveUnreachableKeys(SimplifierTool tool, Stamp valueStamp) {
    if (!(valueStamp instanceof IntegerStamp)) {
        return false;
    }
    IntegerStamp integerStamp = (IntegerStamp) valueStamp;
    if (integerStamp.isUnrestricted()) {
        return false;
    }
    List<KeyData> newKeyDatas = new ArrayList<>(keys.length);
    ArrayList<AbstractBeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
    for (int i = 0; i < keys.length; i++) {
        if (integerStamp.contains(keys[i]) && keySuccessor(i) != defaultSuccessor()) {
            newKeyDatas.add(new KeyData(keys[i], keyProbabilities[i], addNewSuccessor(keySuccessor(i), newSuccessors)));
        }
    }
    if (newKeyDatas.size() == keys.length) {
        /* All keys are reachable. */
        return false;
    } else if (newKeyDatas.size() == 0) {
        if (tool != null) {
            tool.addToWorkList(defaultSuccessor());
        }
        graph().removeSplitPropagate(this, defaultSuccessor());
        return true;
    } else {
        int newDefaultSuccessor = addNewSuccessor(defaultSuccessor(), newSuccessors);
        double newDefaultProbability = keyProbabilities[keyProbabilities.length - 1];
        doReplace(value(), newKeyDatas, newSuccessors, newDefaultSuccessor, newDefaultProbability);
        return true;
    }
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ArrayList(java.util.ArrayList) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 3 with IntegerStamp

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

the class NewArrayNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    if (hasNoUsages()) {
        NodeView view = NodeView.from(tool);
        Stamp lengthStamp = length().stamp(view);
        if (lengthStamp instanceof IntegerStamp) {
            IntegerStamp lengthIntegerStamp = (IntegerStamp) lengthStamp;
            if (lengthIntegerStamp.isPositive()) {
                GraphUtil.removeFixedWithUnusedInputs(this);
                return;
            }
        }
        // RuntimeConstraint
        if (graph().getGuardsStage().allowsFloatingGuards()) {
            LogicNode lengthNegativeCondition = CompareNode.createCompareNode(graph(), CanonicalCondition.LT, length(), ConstantNode.forInt(0, graph()), tool.getConstantReflection(), view);
            // we do not have a non-deopting path for that at the moment so action=None.
            FixedGuardNode guard = graph().add(new FixedGuardNode(lengthNegativeCondition, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.None, true));
            graph().replaceFixedWithFixed(this, guard);
        }
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) LogicNode(org.graalvm.compiler.nodes.LogicNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 4 with IntegerStamp

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

the class BitScanForwardNode method foldStamp.

@Override
public Stamp foldStamp(Stamp newStamp) {
    assert newStamp.isCompatible(getValue().stamp(NodeView.DEFAULT));
    IntegerStamp valueStamp = (IntegerStamp) newStamp;
    int min;
    int max;
    long mask = CodeUtil.mask(valueStamp.getBits());
    int firstAlwaysSetBit = scan(valueStamp.downMask() & mask);
    int firstMaybeSetBit = scan(valueStamp.upMask() & mask);
    if (firstAlwaysSetBit == -1) {
        int lastMaybeSetBit = BitScanReverseNode.scan(valueStamp.upMask() & mask);
        min = firstMaybeSetBit;
        max = lastMaybeSetBit;
    } else {
        min = firstMaybeSetBit;
        max = firstAlwaysSetBit;
    }
    return StampFactory.forInteger(JavaKind.Int, min, max);
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 5 with IntegerStamp

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

the class BitScanReverseNode method foldStamp.

@Override
public Stamp foldStamp(Stamp newStamp) {
    assert newStamp.isCompatible(getValue().stamp(NodeView.DEFAULT));
    IntegerStamp valueStamp = (IntegerStamp) newStamp;
    int min;
    int max;
    long mask = CodeUtil.mask(valueStamp.getBits());
    int lastAlwaysSetBit = scan(valueStamp.downMask() & mask);
    if (lastAlwaysSetBit == -1) {
        int firstMaybeSetBit = BitScanForwardNode.scan(valueStamp.upMask() & mask);
        min = firstMaybeSetBit;
    } else {
        min = lastAlwaysSetBit;
    }
    int lastMaybeSetBit = scan(valueStamp.upMask() & mask);
    max = lastMaybeSetBit;
    return StampFactory.forInteger(JavaKind.Int, min, max);
}
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