Search in sources :

Example 41 with IntegerStamp

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

the class IntegerAddExactNode method foldStamp.

@Override
public Stamp foldStamp(Stamp stampX, Stamp stampY) {
    IntegerStamp a = (IntegerStamp) stampX;
    IntegerStamp b = (IntegerStamp) stampY;
    int bits = a.getBits();
    assert bits == b.getBits();
    long defaultMask = CodeUtil.mask(bits);
    long variableBits = (a.downMask() ^ a.upMask()) | (b.downMask() ^ b.upMask());
    long variableBitsWithCarry = variableBits | (carryBits(a.downMask(), b.downMask()) ^ carryBits(a.upMask(), b.upMask()));
    long newDownMask = (a.downMask() + b.downMask()) & ~variableBitsWithCarry;
    long newUpMask = (a.downMask() + b.downMask()) | variableBitsWithCarry;
    newDownMask &= defaultMask;
    newUpMask &= defaultMask;
    long newLowerBound;
    long newUpperBound;
    boolean lowerOverflowsPositively = addOverflowsPositively(a.lowerBound(), b.lowerBound(), bits);
    boolean upperOverflowsPositively = addOverflowsPositively(a.upperBound(), b.upperBound(), bits);
    boolean lowerOverflowsNegatively = addOverflowsNegatively(a.lowerBound(), b.lowerBound(), bits);
    boolean upperOverflowsNegatively = addOverflowsNegatively(a.upperBound(), b.upperBound(), bits);
    if (lowerOverflowsPositively) {
        newLowerBound = CodeUtil.maxValue(bits);
    } else if (lowerOverflowsNegatively) {
        newLowerBound = CodeUtil.minValue(bits);
    } else {
        newLowerBound = CodeUtil.signExtend((a.lowerBound() + b.lowerBound()) & defaultMask, bits);
    }
    if (upperOverflowsPositively) {
        newUpperBound = CodeUtil.maxValue(bits);
    } else if (upperOverflowsNegatively) {
        newUpperBound = CodeUtil.minValue(bits);
    } else {
        newUpperBound = CodeUtil.signExtend((a.upperBound() + b.upperBound()) & defaultMask, bits);
    }
    IntegerStamp limit = StampFactory.forInteger(bits, newLowerBound, newUpperBound);
    newUpMask &= limit.upMask();
    newUpperBound = CodeUtil.signExtend(newUpperBound & newUpMask, bits);
    newDownMask |= limit.downMask();
    newLowerBound |= newDownMask;
    return IntegerStamp.create(bits, newLowerBound, newUpperBound, newDownMask, newUpMask);
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 42 with IntegerStamp

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

the class AMD64AddressNode method canonicalizeIndex.

public void canonicalizeIndex(SimplifierTool tool) {
    if (index instanceof AddNode && ((IntegerStamp) index.stamp(NodeView.DEFAULT)).getBits() == 64) {
        AddNode add = (AddNode) index;
        ValueNode valX = add.getX();
        if (valX instanceof PhiNode) {
            PhiNode phi = (PhiNode) valX;
            if (phi.merge() instanceof LoopBeginNode) {
                LoopBeginNode loopNode = (LoopBeginNode) phi.merge();
                if (!loopNode.isSimpleLoop()) {
                    ValueNode valY = add.getY();
                    if (valY instanceof ConstantNode) {
                        int addBy = valY.asJavaConstant().asInt();
                        displacement = displacement + scale.value * addBy;
                        replaceFirstInput(index, phi);
                        tool.addToWorkList(index);
                    }
                }
            }
        }
    }
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 43 with IntegerStamp

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

the class UnsignedRightShiftNode method create.

public static ValueNode create(ValueNode x, ValueNode y, NodeView view) {
    ArithmeticOpTable.ShiftOp<UShr> op = ArithmeticOpTable.forStamp(x.stamp(view)).getUShr();
    Stamp stamp = op.foldStamp(x.stamp(view), (IntegerStamp) y.stamp(view));
    ValueNode value = ShiftNode.canonical(op, stamp, x, y, view);
    if (value != null) {
        return value;
    }
    return canonical(null, op, stamp, x, y, view);
}
Also used : ArithmeticOpTable(org.graalvm.compiler.core.common.type.ArithmeticOpTable) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) UShr(org.graalvm.compiler.core.common.type.ArithmeticOpTable.ShiftOp.UShr)

Example 44 with IntegerStamp

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

the class ZeroExtendNode method canonical.

private static ValueNode canonical(ZeroExtendNode zeroExtendNode, ValueNode forValue, int inputBits, int resultBits, NodeView view, boolean alwaysPositive) {
    ZeroExtendNode self = zeroExtendNode;
    if (forValue instanceof ZeroExtendNode) {
        // xxxx -(zero-extend)-> 0000 xxxx -(zero-extend)-> 00000000 0000xxxx
        // ==> xxxx -(zero-extend)-> 00000000 0000xxxx
        ZeroExtendNode other = (ZeroExtendNode) forValue;
        return new ZeroExtendNode(other.getValue(), other.getInputBits(), resultBits, other.isInputAlwaysPositive());
    }
    if (forValue instanceof NarrowNode) {
        NarrowNode narrow = (NarrowNode) forValue;
        Stamp inputStamp = narrow.getValue().stamp(view);
        if (inputStamp instanceof IntegerStamp) {
            IntegerStamp istamp = (IntegerStamp) inputStamp;
            long mask = CodeUtil.mask(PrimitiveStamp.getBits(narrow.stamp(view)));
            if ((istamp.upMask() & ~mask) == 0) {
                if (istamp.getBits() < resultBits) {
                    // Need to keep the zero extend, skip the narrow.
                    return create(narrow.getValue(), resultBits, view);
                } else if (istamp.getBits() > resultBits) {
                    // Need to keep the narrow, skip the zero extend.
                    return NarrowNode.create(narrow.getValue(), resultBits, view);
                } else {
                    assert istamp.getBits() == resultBits;
                    // Just return the original value.
                    return narrow.getValue();
                }
            }
        }
    }
    if (self == null) {
        self = new ZeroExtendNode(forValue, inputBits, resultBits, alwaysPositive);
    }
    return self;
}
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) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 45 with IntegerStamp

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

the class NarrowNode method canonical.

@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
    NodeView view = NodeView.from(tool);
    ValueNode ret = super.canonical(tool, forValue);
    if (ret != this) {
        return ret;
    }
    if (forValue instanceof NarrowNode) {
        // zzzzzzzz yyyyxxxx -(narrow)-> yyyyxxxx -(narrow)-> xxxx
        // ==> zzzzzzzz yyyyxxxx -(narrow)-> xxxx
        NarrowNode other = (NarrowNode) forValue;
        return new NarrowNode(other.getValue(), other.getInputBits(), getResultBits());
    } else if (forValue instanceof IntegerConvertNode) {
        // SignExtendNode or ZeroExtendNode
        IntegerConvertNode<?, ?> other = (IntegerConvertNode<?, ?>) forValue;
        if (other.getValue().hasExactlyOneUsage() && other.hasMoreThanOneUsage()) {
            // If the convert's usage count is <=1, it will be dead code eliminated.
            return this;
        }
        if (getResultBits() == other.getInputBits()) {
            // ==> no-op
            return other.getValue();
        } else if (getResultBits() < other.getInputBits()) {
            // ==> yyyyxxxx -(narrow)-> xxxx
            return new NarrowNode(other.getValue(), other.getInputBits(), getResultBits());
        } else {
            if (other instanceof SignExtendNode) {
                // ==> sxxx -(sign-extend)-> sssssxxx
                return SignExtendNode.create(other.getValue(), other.getInputBits(), getResultBits(), view);
            } else if (other instanceof ZeroExtendNode) {
                // ==> xxxx -(zero-extend)-> 0000xxxx
                return new ZeroExtendNode(other.getValue(), other.getInputBits(), getResultBits(), ((ZeroExtendNode) other).isInputAlwaysPositive());
            }
        }
    } else if (forValue instanceof AndNode) {
        AndNode andNode = (AndNode) forValue;
        IntegerStamp yStamp = (IntegerStamp) andNode.getY().stamp(view);
        IntegerStamp xStamp = (IntegerStamp) andNode.getX().stamp(view);
        long relevantMask = CodeUtil.mask(this.getResultBits());
        if ((relevantMask & yStamp.downMask()) == relevantMask) {
            return create(andNode.getX(), this.getResultBits(), view);
        } else if ((relevantMask & xStamp.downMask()) == relevantMask) {
            return create(andNode.getY(), this.getResultBits(), view);
        }
    }
    return this;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView)

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