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);
}
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;
}
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;
}
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;
}
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);
}
}
}
Aggregations