Search in sources :

Example 46 with IntegerStamp

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

the class RightShiftNode method create.

public static ValueNode create(ValueNode x, ValueNode y, NodeView view) {
    ArithmeticOpTable.ShiftOp<Shr> op = ArithmeticOpTable.forStamp(x.stamp(view)).getShr();
    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) Shr(org.graalvm.compiler.core.common.type.ArithmeticOpTable.ShiftOp.Shr)

Example 47 with IntegerStamp

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

the class RightShiftNode method canonical.

private static ValueNode canonical(RightShiftNode rightShiftNode, ArithmeticOpTable.ShiftOp<Shr> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
    RightShiftNode self = rightShiftNode;
    if (forX.stamp(view) instanceof IntegerStamp && ((IntegerStamp) forX.stamp(view)).isPositive()) {
        return new UnsignedRightShiftNode(forX, forY);
    }
    if (forY.isConstant()) {
        int amount = forY.asJavaConstant().asInt();
        int originalAmout = amount;
        int mask = op.getShiftAmountMask(stamp);
        amount &= mask;
        if (amount == 0) {
            return forX;
        }
        if (forX instanceof ShiftNode) {
            ShiftNode<?> other = (ShiftNode<?>) forX;
            if (other.getY().isConstant()) {
                int otherAmount = other.getY().asJavaConstant().asInt() & mask;
                if (other instanceof RightShiftNode) {
                    int total = amount + otherAmount;
                    if (total != (total & mask)) {
                        assert other.getX().stamp(view) instanceof IntegerStamp;
                        IntegerStamp istamp = (IntegerStamp) other.getX().stamp(view);
                        if (istamp.isPositive()) {
                            return ConstantNode.forIntegerKind(stamp.getStackKind(), 0);
                        }
                        if (istamp.isStrictlyNegative()) {
                            return ConstantNode.forIntegerKind(stamp.getStackKind(), -1L);
                        }
                        /*
                             * if we cannot replace both shifts with a constant, replace them by a
                             * full shift for this kind
                             */
                        assert total >= mask;
                        return new RightShiftNode(other.getX(), ConstantNode.forInt(mask));
                    }
                    return new RightShiftNode(other.getX(), ConstantNode.forInt(total));
                }
            }
        }
        if (originalAmout != amount) {
            return new RightShiftNode(forX, ConstantNode.forInt(amount));
        }
    }
    if (self == null) {
        self = new RightShiftNode(forX, forY);
    }
    return self;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 48 with IntegerStamp

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

the class ShiftNode method isNarrowable.

@Override
public boolean isNarrowable(int resultBits) {
    assert CodeUtil.isPowerOf2(resultBits);
    int narrowMask = resultBits - 1;
    int wideMask = getShiftAmountMask();
    assert (wideMask & narrowMask) == narrowMask : String.format("wideMask %x should be wider than narrowMask %x", wideMask, narrowMask);
    /*
         * Shifts are special because narrowing them also changes the implicit mask of the shift
         * amount. We can narrow only if (y & wideMask) == (y & narrowMask) for all possible values
         * of y.
         */
    IntegerStamp yStamp = (IntegerStamp) getY().stamp(NodeView.DEFAULT);
    return (yStamp.upMask() & (wideMask & ~narrowMask)) == 0;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp)

Example 49 with IntegerStamp

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

the class SignedDivNode method canonical.

public static ValueNode canonical(ValueNode forX, long c, NodeView view) {
    if (c == 1) {
        return forX;
    }
    if (c == -1) {
        return NegateNode.create(forX, view);
    }
    long abs = Math.abs(c);
    if (CodeUtil.isPowerOf2(abs) && forX.stamp(view) instanceof IntegerStamp) {
        ValueNode dividend = forX;
        IntegerStamp stampX = (IntegerStamp) forX.stamp(view);
        int log2 = CodeUtil.log2(abs);
        // no rounding if dividend is positive or if its low bits are always 0
        if (stampX.canBeNegative() || (stampX.upMask() & (abs - 1)) != 0) {
            int bits = PrimitiveStamp.getBits(forX.stamp(view));
            RightShiftNode sign = new RightShiftNode(forX, ConstantNode.forInt(bits - 1));
            UnsignedRightShiftNode round = new UnsignedRightShiftNode(sign, ConstantNode.forInt(bits - log2));
            dividend = BinaryArithmeticNode.add(dividend, round, view);
        }
        RightShiftNode shift = new RightShiftNode(dividend, ConstantNode.forInt(log2));
        if (c < 0) {
            return NegateNode.create(shift, view);
        }
        return shift;
    }
    return null;
}
Also used : IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 50 with IntegerStamp

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

the class SPARCIntegerCompareCanonicalizationPhase method min32.

private static void min32(CompareNode enode, ValueNode v) {
    Stamp s = v.stamp(NodeView.DEFAULT);
    if (s instanceof IntegerStamp) {
        int bits = ((IntegerStamp) s).getBits();
        if (bits != 32 && bits != 64) {
            if (bits <= 32) {
                bits = 32;
            } else {
                bits = 64;
            }
            ValueNode replacement;
            if (v instanceof ConstantNode) {
                JavaConstant newConst;
                if (bits == 32) {
                    newConst = JavaConstant.forInt(v.asJavaConstant().asInt());
                } else if (bits == 64) {
                    newConst = JavaConstant.forLong(v.asJavaConstant().asLong());
                } else {
                    throw GraalError.shouldNotReachHere();
                }
                long mask = CodeUtil.mask(bits);
                replacement = v.graph().addOrUnique(new ConstantNode(newConst, IntegerStamp.stampForMask(bits, newConst.asLong() & mask, newConst.asLong() & mask)));
            } else {
                replacement = v.graph().addOrUnique(new SignExtendNode(v, bits));
            }
            v.replaceAtUsages(replacement, x -> x == enode);
        }
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

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