use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class AMD64HotSpotAddressLowering method signExtend.
/**
* Create a sign extend for {@code input}, or zero extend if {@code input} can be proven
* positive.
*/
private static ValueNode signExtend(ValueNode input, LoopEx loop) {
StructuredGraph graph = input.graph();
if (input instanceof PhiNode) {
EconomicMap<Node, InductionVariable> ivs = loop.getInductionVariables();
InductionVariable inductionVariable = ivs.get(input);
if (inductionVariable != null && inductionVariable instanceof BasicInductionVariable) {
CountedLoopInfo countedLoopInfo = loop.counted();
IntegerStamp initStamp = (IntegerStamp) inductionVariable.initNode().stamp(NodeView.DEFAULT);
if (initStamp.isPositive()) {
if (inductionVariable.isConstantExtremum()) {
long init = inductionVariable.constantInit();
long stride = inductionVariable.constantStride();
long extremum = inductionVariable.constantExtremum();
if (init >= 0 && extremum >= 0) {
long shortestTrip = (extremum - init) / stride + 1;
if (countedLoopInfo.constantMaxTripCount().equals(shortestTrip)) {
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
}
}
}
if (countedLoopInfo.getCounter() == inductionVariable && inductionVariable.direction() == InductionVariable.Direction.Up && countedLoopInfo.getOverFlowGuard() != null) {
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
}
}
}
}
return input.graph().maybeAddOrUnique(SignExtendNode.create(input, ADDRESS_BITS, NodeView.DEFAULT));
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class IntegerSwitchNode method tryRemoveUnreachableKeys.
/**
* Remove unreachable keys from the switch based on the stamp of the value, i.e., based on the
* known range of the switch value.
*/
public boolean tryRemoveUnreachableKeys(SimplifierTool tool, Stamp valueStamp) {
if (!(valueStamp instanceof IntegerStamp)) {
return false;
}
IntegerStamp integerStamp = (IntegerStamp) valueStamp;
if (integerStamp.isUnrestricted()) {
return false;
}
List<KeyData> newKeyDatas = new ArrayList<>(keys.length);
ArrayList<AbstractBeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
for (int i = 0; i < keys.length; i++) {
if (integerStamp.contains(keys[i]) && keySuccessor(i) != defaultSuccessor()) {
newKeyDatas.add(new KeyData(keys[i], keyProbabilities[i], addNewSuccessor(keySuccessor(i), newSuccessors)));
}
}
if (newKeyDatas.size() == keys.length) {
/* All keys are reachable. */
return false;
} else if (newKeyDatas.size() == 0) {
if (tool != null) {
tool.addToWorkList(defaultSuccessor());
}
graph().removeSplitPropagate(this, defaultSuccessor());
return true;
} else {
int newDefaultSuccessor = addNewSuccessor(defaultSuccessor(), newSuccessors);
double newDefaultProbability = keyProbabilities[keyProbabilities.length - 1];
doReplace(value(), newKeyDatas, newSuccessors, newDefaultSuccessor, newDefaultProbability);
return true;
}
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class NewArrayNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
if (hasNoUsages()) {
NodeView view = NodeView.from(tool);
Stamp lengthStamp = length().stamp(view);
if (lengthStamp instanceof IntegerStamp) {
IntegerStamp lengthIntegerStamp = (IntegerStamp) lengthStamp;
if (lengthIntegerStamp.isPositive()) {
GraphUtil.removeFixedWithUnusedInputs(this);
return;
}
}
// RuntimeConstraint
if (graph().getGuardsStage().allowsFloatingGuards()) {
LogicNode lengthNegativeCondition = CompareNode.createCompareNode(graph(), CanonicalCondition.LT, length(), ConstantNode.forInt(0, graph()), tool.getConstantReflection(), view);
// we do not have a non-deopting path for that at the moment so action=None.
FixedGuardNode guard = graph().add(new FixedGuardNode(lengthNegativeCondition, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.None, true));
graph().replaceFixedWithFixed(this, guard);
}
}
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class BitScanForwardNode method foldStamp.
@Override
public Stamp foldStamp(Stamp newStamp) {
assert newStamp.isCompatible(getValue().stamp(NodeView.DEFAULT));
IntegerStamp valueStamp = (IntegerStamp) newStamp;
int min;
int max;
long mask = CodeUtil.mask(valueStamp.getBits());
int firstAlwaysSetBit = scan(valueStamp.downMask() & mask);
int firstMaybeSetBit = scan(valueStamp.upMask() & mask);
if (firstAlwaysSetBit == -1) {
int lastMaybeSetBit = BitScanReverseNode.scan(valueStamp.upMask() & mask);
min = firstMaybeSetBit;
max = lastMaybeSetBit;
} else {
min = firstMaybeSetBit;
max = firstAlwaysSetBit;
}
return StampFactory.forInteger(JavaKind.Int, min, max);
}
use of org.graalvm.compiler.core.common.type.IntegerStamp in project graal by oracle.
the class BitScanReverseNode method foldStamp.
@Override
public Stamp foldStamp(Stamp newStamp) {
assert newStamp.isCompatible(getValue().stamp(NodeView.DEFAULT));
IntegerStamp valueStamp = (IntegerStamp) newStamp;
int min;
int max;
long mask = CodeUtil.mask(valueStamp.getBits());
int lastAlwaysSetBit = scan(valueStamp.downMask() & mask);
if (lastAlwaysSetBit == -1) {
int firstMaybeSetBit = BitScanForwardNode.scan(valueStamp.upMask() & mask);
min = firstMaybeSetBit;
} else {
min = lastAlwaysSetBit;
}
int lastMaybeSetBit = scan(valueStamp.upMask() & mask);
max = lastMaybeSetBit;
return StampFactory.forInteger(JavaKind.Int, min, max);
}
Aggregations