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, ValueNode forX, ValueNode forY) {
Stamp s = getSucceedingStampForX(mirror, strict, xStampGeneric, yStampGeneric);
if (s != null && s.isUnrestricted()) {
s = null;
}
if (forY instanceof AddNode && xStampGeneric instanceof IntegerStamp) {
IntegerStamp xStamp = (IntegerStamp) xStampGeneric;
AddNode addNode = (AddNode) forY;
IntegerStamp aStamp = null;
if (addNode.getX() == forX && addNode.getY().stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
// x < x + a
aStamp = (IntegerStamp) addNode.getY().stamp(NodeView.DEFAULT);
} else if (addNode.getY() == forX && addNode.getX().stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
// x < a + x
aStamp = (IntegerStamp) addNode.getX().stamp(NodeView.DEFAULT);
}
if (aStamp != null) {
IntegerStamp result = getOp().getSucceedingStampForXLowerXPlusA(mirror, strict, aStamp);
result = (IntegerStamp) xStamp.tryImproveWith(result);
if (result != null) {
if (s != null) {
s = s.improveWith(result);
} else {
s = result;
}
}
}
}
return s;
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class LoopBeginNode method getSelfIncrements.
/**
* Returns an array with one entry for each input of the phi, which is either
* {@link #NO_INCREMENT} or the increment, i.e., the value by which the phi is incremented in
* the corresponding branch.
*/
private static int[] getSelfIncrements(PhiNode phi) {
int[] selfIncrement = new int[phi.valueCount()];
for (int i = 0; i < phi.valueCount(); i++) {
ValueNode input = phi.valueAt(i);
long increment = NO_INCREMENT;
if (input != null && input instanceof AddNode && input.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
AddNode add = (AddNode) input;
if (add.getX() == phi && add.getY().isConstant()) {
increment = add.getY().asJavaConstant().asLong();
} else if (add.getY() == phi && add.getX().isConstant()) {
increment = add.getX().asJavaConstant().asLong();
}
} else if (input == phi) {
increment = 0;
}
if (increment < Integer.MIN_VALUE || increment > Integer.MAX_VALUE || increment == NO_INCREMENT) {
increment = NO_INCREMENT;
}
selfIncrement[i] = (int) increment;
}
return selfIncrement;
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class CountedLoopInfo method createOverFlowGuard.
@SuppressWarnings("try")
public GuardingNode createOverFlowGuard() {
GuardingNode overflowGuard = getOverFlowGuard();
if (overflowGuard != null) {
return overflowGuard;
}
try (DebugCloseable position = loop.loopBegin().withNodeSourcePosition()) {
IntegerStamp stamp = (IntegerStamp) iv.valueNode().stamp(NodeView.DEFAULT);
StructuredGraph graph = iv.valueNode().graph();
// we use a negated guard with a < condition to achieve a >=
CompareNode cond;
ConstantNode one = ConstantNode.forIntegerStamp(stamp, 1, graph);
if (iv.direction() == Direction.Up) {
ValueNode v1 = sub(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.maxValue(stamp.getBits()), graph), sub(graph, iv.strideNode(), one));
if (oneOff) {
v1 = sub(graph, v1, one);
}
cond = graph.unique(new IntegerLessThanNode(v1, end));
} else {
assert iv.direction() == Direction.Down;
ValueNode v1 = add(graph, ConstantNode.forIntegerStamp(stamp, CodeUtil.minValue(stamp.getBits()), graph), sub(graph, one, iv.strideNode()));
if (oneOff) {
v1 = add(graph, v1, one);
}
cond = graph.unique(new IntegerLessThanNode(end, v1));
}
assert graph.getGuardsStage().allowsFloatingGuards();
overflowGuard = graph.unique(new GuardNode(cond, AbstractBeginNode.prevBegin(loop.entryPoint()), DeoptimizationReason.LoopLimitCheck, DeoptimizationAction.InvalidateRecompile, true, // TODO gd: use speculation
JavaConstant.NULL_POINTER));
loop.loopBegin().setOverflowGuard(overflowGuard);
return overflowGuard;
}
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerExactFoldTest method testFolding.
@Test
public void testFolding() {
StructuredGraph graph = prepareGraph();
IntegerStamp a = StampFactory.forInteger(bits, lowerBoundA, upperBoundA);
IntegerStamp b = StampFactory.forInteger(bits, lowerBoundB, upperBoundB);
List<ParameterNode> params = graph.getNodes(ParameterNode.TYPE).snapshot();
params.get(0).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(0), a)), x -> x instanceof IntegerExactArithmeticNode);
params.get(1).replaceAtMatchingUsages(graph.addOrUnique(new PiNode(params.get(1), b)), x -> x instanceof IntegerExactArithmeticNode);
Node originalNode = graph.getNodes().filter(x -> x instanceof IntegerExactArithmeticNode).first();
assertNotNull("original node must be in the graph", originalNode);
new CanonicalizerPhase().apply(graph, getDefaultHighTierContext());
ValueNode node = findNode(graph);
boolean overflowExpected = node instanceof IntegerExactArithmeticNode;
IntegerStamp resultStamp = (IntegerStamp) node.stamp(NodeView.DEFAULT);
operation.verifyOverflow(lowerBoundA, upperBoundA, lowerBoundB, upperBoundB, bits, overflowExpected, resultStamp);
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerSubOverflowsTest method testOverflowCheckStamp06.
@Test
public void testOverflowCheckStamp06() {
IntegerStamp s1 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
IntegerStamp s2 = StampFactory.forInteger(8, Byte.MIN_VALUE, Byte.MIN_VALUE);
Assert.assertFalse(IntegerStamp.subtractionCanOverflow(s1, s2));
}
Aggregations