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