use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerSubOverflowsTest method testOverflowCheckStamp07.
@Test
public void testOverflowCheckStamp07() {
IntegerStamp s1 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(8, 1, 1);
Assert.assertTrue(IntegerStamp.subtractionCanOverflow(s1, s2));
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IfNode method checkForUnsignedCompare.
/**
* Recognize a couple patterns that can be merged into an unsigned compare.
*
* @param tool
* @return true if a replacement was done.
*/
private boolean checkForUnsignedCompare(SimplifierTool tool) {
assert trueSuccessor().hasNoUsages() && falseSuccessor().hasNoUsages();
if (condition() instanceof IntegerLessThanNode) {
NodeView view = NodeView.from(tool);
IntegerLessThanNode lessThan = (IntegerLessThanNode) condition();
Constant y = lessThan.getY().stamp(view).asConstant();
if (y instanceof PrimitiveConstant && ((PrimitiveConstant) y).asLong() == 0 && falseSuccessor().next() instanceof IfNode) {
IfNode ifNode2 = (IfNode) falseSuccessor().next();
if (ifNode2.condition() instanceof IntegerLessThanNode) {
IntegerLessThanNode lessThan2 = (IntegerLessThanNode) ifNode2.condition();
AbstractBeginNode falseSucc = ifNode2.falseSuccessor();
AbstractBeginNode trueSucc = ifNode2.trueSuccessor();
IntegerBelowNode below = null;
/*
* Convert x >= 0 && x < positive which is represented as !(x < 0) && x <
* <positive> into an unsigned compare.
*/
if (lessThan2.getX() == lessThan.getX() && lessThan2.getY().stamp(view) instanceof IntegerStamp && ((IntegerStamp) lessThan2.getY().stamp(view)).isPositive() && sameDestination(trueSuccessor(), ifNode2.falseSuccessor)) {
below = graph().unique(new IntegerBelowNode(lessThan2.getX(), lessThan2.getY()));
// swap direction
AbstractBeginNode tmp = falseSucc;
falseSucc = trueSucc;
trueSucc = tmp;
} else if (lessThan2.getY() == lessThan.getX() && sameDestination(trueSuccessor(), ifNode2.trueSuccessor)) {
/*
* Convert x >= 0 && x <= positive which is represented as !(x < 0) &&
* !(<positive> > x), into x <| positive + 1. This can only be done for
* constants since there isn't a IntegerBelowEqualThanNode but that doesn't
* appear to be interesting.
*/
JavaConstant positive = lessThan2.getX().asJavaConstant();
if (positive != null && positive.asLong() > 0 && positive.asLong() < positive.getJavaKind().getMaxValue()) {
ConstantNode newLimit = ConstantNode.forIntegerStamp(lessThan2.getX().stamp(view), positive.asLong() + 1, graph());
below = graph().unique(new IntegerBelowNode(lessThan.getX(), newLimit));
}
}
if (below != null) {
ifNode2.setTrueSuccessor(null);
ifNode2.setFalseSuccessor(null);
IfNode newIfNode = graph().add(new IfNode(below, falseSucc, trueSucc, 1 - trueSuccessorProbability));
// Remove the < 0 test.
tool.deleteBranch(trueSuccessor);
graph().removeSplit(this, falseSuccessor);
// Replace the second test with the new one.
ifNode2.predecessor().replaceFirstSuccessor(ifNode2, newIfNode);
ifNode2.safeDelete();
return true;
}
}
}
}
return false;
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerLowerThanNode method getSucceedingStampForX.
private Stamp getSucceedingStampForX(boolean mirror, boolean strict, Stamp xStampGeneric, Stamp yStampGeneric) {
if (xStampGeneric instanceof IntegerStamp) {
IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
if (yStampGeneric instanceof IntegerStamp) {
IntegerStamp yStamp = (IntegerStamp) yStampGeneric;
assert yStamp.getBits() == xStamp.getBits();
Stamp s = getOp().getSucceedingStampForX(xStamp, yStamp, mirror, strict);
if (s != null) {
return s;
}
}
}
return null;
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerTestNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
if (forX.isConstant() && forY.isConstant()) {
return LogicConstantNode.forBoolean((forX.asJavaConstant().asLong() & forY.asJavaConstant().asLong()) == 0);
}
if (forX.stamp(view) instanceof IntegerStamp && forY.stamp(view) instanceof IntegerStamp) {
IntegerStamp xStamp = (IntegerStamp) forX.stamp(view);
IntegerStamp yStamp = (IntegerStamp) forY.stamp(view);
if ((xStamp.upMask() & yStamp.upMask()) == 0) {
return LogicConstantNode.tautology();
} else if ((xStamp.downMask() & yStamp.downMask()) != 0) {
return LogicConstantNode.contradiction();
}
}
return this;
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerTestNode method getSucceedingStamp.
private static Stamp getSucceedingStamp(boolean negated, Stamp xStampGeneric, Stamp otherStampGeneric) {
if (xStampGeneric instanceof IntegerStamp && otherStampGeneric instanceof IntegerStamp) {
IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
IntegerStamp otherStamp = (IntegerStamp) otherStampGeneric;
if (negated) {
if (Long.bitCount(otherStamp.upMask()) == 1) {
long newDownMask = xStamp.downMask() | otherStamp.upMask();
if (xStamp.downMask() != newDownMask) {
return IntegerStamp.stampForMask(xStamp.getBits(), newDownMask, xStamp.upMask()).join(xStamp);
}
}
} else {
long restrictedUpMask = ((~otherStamp.downMask()) & xStamp.upMask());
if (xStamp.upMask() != restrictedUpMask) {
return IntegerStamp.stampForMask(xStamp.getBits(), xStamp.downMask(), restrictedUpMask).join(xStamp);
}
}
}
return null;
}
Aggregations