Search in sources :

Example 1 with BasicInductionVariable

use of org.graalvm.compiler.nodes.loop.BasicInductionVariable 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() && countedLoopInfo.counterNeverOverflows()) {
                    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.getLimitCheckedIV() == inductionVariable && inductionVariable.direction() == InductionVariable.Direction.Up && (countedLoopInfo.getOverFlowGuard() != null || countedLoopInfo.counterNeverOverflows())) {
                    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) 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.nodes.loop.CountedLoopInfo) BasicInductionVariable(org.graalvm.compiler.nodes.loop.BasicInductionVariable) DerivedInductionVariable(org.graalvm.compiler.nodes.loop.DerivedInductionVariable) InductionVariable(org.graalvm.compiler.nodes.loop.InductionVariable) BasicInductionVariable(org.graalvm.compiler.nodes.loop.BasicInductionVariable) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode)

Aggregations

AMD64AddressNode (org.graalvm.compiler.core.amd64.AMD64AddressNode)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 Node (org.graalvm.compiler.graph.Node)1 CompressionNode (org.graalvm.compiler.nodes.CompressionNode)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 PhiNode (org.graalvm.compiler.nodes.PhiNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 AddNode (org.graalvm.compiler.nodes.calc.AddNode)1 SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)1 ZeroExtendNode (org.graalvm.compiler.nodes.calc.ZeroExtendNode)1 BasicInductionVariable (org.graalvm.compiler.nodes.loop.BasicInductionVariable)1 CountedLoopInfo (org.graalvm.compiler.nodes.loop.CountedLoopInfo)1 DerivedInductionVariable (org.graalvm.compiler.nodes.loop.DerivedInductionVariable)1 InductionVariable (org.graalvm.compiler.nodes.loop.InductionVariable)1 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)1 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)1