use of org.graalvm.compiler.nodes.calc.CompareNode 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.nodes.calc.CompareNode in project graal by oracle.
the class LoopTransformations method updateMainLoopLimit.
private static void updateMainLoopLimit(IfNode preLimit, InductionVariable preIv, LoopFragmentWhole mainLoop) {
// Update the main loops limit test to be different than the post loop
StructuredGraph graph = preLimit.graph();
IfNode mainLimit = mainLoop.getDuplicatedNode(preLimit);
LogicNode ifTest = mainLimit.condition();
CompareNode compareNode = (CompareNode) ifTest;
ValueNode prePhi = preIv.valueNode();
ValueNode mainPhi = mainLoop.getDuplicatedNode(prePhi);
ValueNode preStride = preIv.strideNode();
ValueNode mainStride;
if (preStride instanceof ConstantNode) {
mainStride = preStride;
} else {
mainStride = mainLoop.getDuplicatedNode(preStride);
}
// Fetch the bounds to pose lowering the range by one
ValueNode ub = null;
if (compareNode.getX() == mainPhi) {
ub = compareNode.getY();
} else if (compareNode.getY() == mainPhi) {
ub = compareNode.getX();
} else {
throw GraalError.shouldNotReachHere();
}
// Preloop always performs at least one iteration, so remove that from the main loop.
ValueNode newLimit = sub(graph, ub, mainStride);
// Re-wire the condition with the new limit
compareNode.replaceFirstInput(ub, newLimit);
}
use of org.graalvm.compiler.nodes.calc.CompareNode in project graal by oracle.
the class LoopTransformations method isUnrollableLoop.
public static boolean isUnrollableLoop(LoopEx loop) {
if (!loop.isCounted() || !loop.counted().getCounter().isConstantStride() || !loop.loop().getChildren().isEmpty()) {
return false;
}
LoopBeginNode loopBegin = loop.loopBegin();
LogicNode condition = loop.counted().getLimitTest().condition();
if (!(condition instanceof CompareNode)) {
return false;
}
if (((CompareNode) condition).condition() == CanonicalCondition.EQ) {
condition.getDebug().log(DebugContext.VERBOSE_LEVEL, "isUnrollableLoop %s condition unsupported %s ", loopBegin, ((CompareNode) condition).condition());
return false;
}
if (loopBegin.isMainLoop() || loopBegin.isSimpleLoop()) {
// as well.
if (loop.loop().getBlocks().size() < 3) {
return true;
}
condition.getDebug().log(DebugContext.VERBOSE_LEVEL, "isUnrollableLoop %s too large to unroll %s ", loopBegin, loop.loop().getBlocks().size());
}
return false;
}
use of org.graalvm.compiler.nodes.calc.CompareNode in project graal by oracle.
the class SPARCIntegerCompareCanonicalizationPhase method run.
@Override
protected void run(StructuredGraph graph) {
for (Node n : graph.getNodes()) {
if (n instanceof CompareNode) {
CompareNode enode = (CompareNode) n;
min32(enode, enode.getX());
min32(enode, enode.getY());
}
}
}
use of org.graalvm.compiler.nodes.calc.CompareNode in project graal by oracle.
the class SPARCNodeMatchRules method ifCompareLogicCas.
@MatchRule("(If (ObjectEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (PointerEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (FloatEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (IntegerEquals=compare value LogicCompareAndSwap=cas))")
public ComplexMatchResult ifCompareLogicCas(IfNode root, CompareNode compare, ValueNode value, LogicCompareAndSwapNode cas) {
JavaConstant constant = value.asJavaConstant();
assert compare.condition() == CanonicalCondition.EQ;
if (constant != null && cas.usages().count() == 1) {
long constantValue = constant.asLong();
boolean successIsTrue;
if (constantValue == 0) {
successIsTrue = false;
} else if (constantValue == 1) {
successIsTrue = true;
} else {
return null;
}
return builder -> {
LIRKind kind = getLirKind(cas);
LabelRef trueLabel = getLIRBlock(root.trueSuccessor());
LabelRef falseLabel = getLIRBlock(root.falseSuccessor());
double trueLabelProbability = root.probability(root.trueSuccessor());
Value expectedValue = operand(cas.getExpectedValue());
Value newValue = operand(cas.getNewValue());
SPARCAddressValue address = (SPARCAddressValue) operand(cas.getAddress());
Condition condition = successIsTrue ? Condition.EQ : Condition.NE;
Value result = getLIRGeneratorTool().emitValueCompareAndSwap(address, expectedValue, newValue);
getLIRGeneratorTool().emitCompareBranch(kind.getPlatformKind(), result, expectedValue, condition, false, trueLabel, falseLabel, trueLabelProbability);
return null;
};
}
return null;
}
Aggregations