use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerStampTest method testMaskBasedNarrowing.
@Test
public void testMaskBasedNarrowing() {
IntegerStamp stamp = IntegerStamp.create(32, 1, 2, 0x2, 0x3);
IntegerStamp resultStamp = IntegerStamp.create(32, 2, 2);
assertEquals(resultStamp, stamp);
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerStampTest method testEmpty.
@Test
public void testEmpty() {
IntegerStamp intStamp = StampFactory.forInteger(32);
IntegerStamp longStamp = StampFactory.forInteger(64);
Stamp intEmpty = StampFactory.empty(JavaKind.Int);
Stamp longEmpty = StampFactory.empty(JavaKind.Long);
assertEquals(intStamp.join(intEmpty), intEmpty);
assertEquals(intStamp.meet(intEmpty), intStamp);
assertEquals(longStamp.join(longEmpty), longEmpty);
assertEquals(longStamp.meet(longEmpty), longStamp);
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class LoopEx method detectCounted.
public boolean detectCounted() {
LoopBeginNode loopBegin = loopBegin();
FixedNode next = loopBegin.next();
while (next instanceof FixedGuardNode || next instanceof ValueAnchorNode || next instanceof FullInfopointNode) {
next = ((FixedWithNextNode) next).next();
}
if (next instanceof IfNode) {
IfNode ifNode = (IfNode) next;
boolean negated = false;
if (!loopBegin.isLoopExit(ifNode.falseSuccessor())) {
if (!loopBegin.isLoopExit(ifNode.trueSuccessor())) {
return false;
}
negated = true;
}
LogicNode ifTest = ifNode.condition();
if (!(ifTest instanceof IntegerLessThanNode) && !(ifTest instanceof IntegerEqualsNode)) {
if (ifTest instanceof IntegerBelowNode) {
ifTest.getDebug().log("Ignored potential Counted loop at %s with |<|", loopBegin);
}
return false;
}
CompareNode lessThan = (CompareNode) ifTest;
Condition condition = null;
InductionVariable iv = null;
ValueNode limit = null;
if (isOutsideLoop(lessThan.getX())) {
iv = getInductionVariables().get(lessThan.getY());
if (iv != null) {
condition = lessThan.condition().asCondition().mirror();
limit = lessThan.getX();
}
} else if (isOutsideLoop(lessThan.getY())) {
iv = getInductionVariables().get(lessThan.getX());
if (iv != null) {
condition = lessThan.condition().asCondition();
limit = lessThan.getY();
}
}
if (condition == null) {
return false;
}
if (negated) {
condition = condition.negate();
}
boolean oneOff = false;
switch(condition) {
case EQ:
return false;
case NE:
{
if (!iv.isConstantStride() || Math.abs(iv.constantStride()) != 1) {
return false;
}
IntegerStamp initStamp = (IntegerStamp) iv.initNode().stamp(NodeView.DEFAULT);
IntegerStamp limitStamp = (IntegerStamp) limit.stamp(NodeView.DEFAULT);
if (iv.direction() == Direction.Up) {
if (initStamp.upperBound() > limitStamp.lowerBound()) {
return false;
}
} else if (iv.direction() == Direction.Down) {
if (initStamp.lowerBound() < limitStamp.upperBound()) {
return false;
}
} else {
return false;
}
break;
}
case LE:
oneOff = true;
if (iv.direction() != Direction.Up) {
return false;
}
break;
case LT:
if (iv.direction() != Direction.Up) {
return false;
}
break;
case GE:
oneOff = true;
if (iv.direction() != Direction.Down) {
return false;
}
break;
case GT:
if (iv.direction() != Direction.Down) {
return false;
}
break;
default:
throw GraalError.shouldNotReachHere();
}
counted = new CountedLoopInfo(this, iv, ifNode, limit, oneOff, negated ? ifNode.falseSuccessor() : ifNode.trueSuccessor());
return true;
}
return false;
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class LoopEx method findInductionVariables.
/**
* Collect all the basic induction variables for the loop and the find any induction variables
* which are derived from the basic ones.
*
* @param loop
* @return a map from node to induction variable
*/
private static EconomicMap<Node, InductionVariable> findInductionVariables(LoopEx loop) {
EconomicMap<Node, InductionVariable> ivs = EconomicMap.create(Equivalence.IDENTITY);
Queue<InductionVariable> scanQueue = new LinkedList<>();
LoopBeginNode loopBegin = loop.loopBegin();
AbstractEndNode forwardEnd = loopBegin.forwardEnd();
for (PhiNode phi : loopBegin.valuePhis()) {
ValueNode backValue = phi.singleBackValueOrThis();
if (backValue == phi) {
continue;
}
ValueNode stride = addSub(loop, backValue, phi);
if (stride != null) {
BasicInductionVariable biv = new BasicInductionVariable(loop, (ValuePhiNode) phi, phi.valueAt(forwardEnd), stride, (BinaryArithmeticNode<?>) backValue);
ivs.put(phi, biv);
scanQueue.add(biv);
}
}
while (!scanQueue.isEmpty()) {
InductionVariable baseIv = scanQueue.remove();
ValueNode baseIvNode = baseIv.valueNode();
for (ValueNode op : baseIvNode.usages().filter(ValueNode.class)) {
if (loop.isOutsideLoop(op)) {
continue;
}
if (op.usages().count() == 1 && op.usages().first() == baseIvNode) {
/*
* This is just the base induction variable increment with no other uses so
* don't bother reporting it.
*/
continue;
}
InductionVariable iv = null;
ValueNode offset = addSub(loop, op, baseIvNode);
ValueNode scale;
if (offset != null) {
iv = new DerivedOffsetInductionVariable(loop, baseIv, offset, (BinaryArithmeticNode<?>) op);
} else if (op instanceof NegateNode) {
iv = new DerivedScaledInductionVariable(loop, baseIv, (NegateNode) op);
} else if ((scale = mul(loop, op, baseIvNode)) != null) {
iv = new DerivedScaledInductionVariable(loop, baseIv, scale, op);
} else {
boolean isValidConvert = op instanceof PiNode || op instanceof SignExtendNode;
if (!isValidConvert && op instanceof ZeroExtendNode) {
ZeroExtendNode zeroExtendNode = (ZeroExtendNode) op;
isValidConvert = zeroExtendNode.isInputAlwaysPositive() || ((IntegerStamp) zeroExtendNode.stamp(NodeView.DEFAULT)).isPositive();
}
if (isValidConvert) {
iv = new DerivedConvertedInductionVariable(loop, baseIv, op.stamp(NodeView.DEFAULT), op);
}
}
if (iv != null) {
ivs.put(op, iv);
scanQueue.offer(iv);
}
}
}
return ivs;
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class DefaultJavaLoweringProvider method createArrayIndexAddress.
/**
* Create a PiNode on the index proving that the index is positive. On some platforms this is
* important to allow the index to be used as an int in the address mode.
*/
public AddressNode createArrayIndexAddress(StructuredGraph graph, ValueNode array, JavaKind elementKind, ValueNode index, GuardingNode boundsCheck) {
IntegerStamp indexStamp = StampFactory.forInteger(32, 0, Integer.MAX_VALUE - 1);
ValueNode positiveIndex = graph.maybeAddOrUnique(PiNode.create(index, indexStamp, boundsCheck != null ? boundsCheck.asNode() : null));
return createArrayAddress(graph, array, elementKind, positiveIndex);
}
Aggregations