use of org.graalvm.compiler.core.common.calc.Condition.EQ in project graal by oracle.
the class LoopPredicationPhase method run.
@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, MidTierContext context) {
DebugContext debug = graph.getDebug();
final SpeculationLog speculationLog = graph.getSpeculationLog();
if (graph.hasLoops() && graph.getGuardsStage().allowsFloatingGuards() && context.getOptimisticOptimizations().useLoopLimitChecks(graph.getOptions()) && speculationLog != null) {
LoopsData data = context.getLoopsDataProvider().getLoopsData(graph);
final ControlFlowGraph cfg = data.getCFG();
try (DebugContext.Scope s = debug.scope("predication", cfg)) {
for (LoopEx loop : data.loops()) {
// Only inner most loops.
if (!loop.loop().getChildren().isEmpty()) {
continue;
}
if (!loop.detectCounted()) {
continue;
}
final FrameState state = loop.loopBegin().stateAfter();
final BytecodePosition pos = new BytecodePosition(null, state.getMethod(), state.bci);
SpeculationLog.SpeculationReason reason = LOOP_PREDICATION.createSpeculationReason(pos);
if (speculationLog.maySpeculate(reason)) {
final CountedLoopInfo counted = loop.counted();
final InductionVariable counter = counted.getLimitCheckedIV();
final Condition condition = ((CompareNode) counted.getLimitTest().condition()).condition().asCondition();
final boolean inverted = loop.counted().isInverted();
if ((((IntegerStamp) counter.valueNode().stamp(NodeView.DEFAULT)).getBits() == 32) && !counted.isUnsignedCheck() && ((condition != NE && condition != EQ) || (counter.isConstantStride() && Math.abs(counter.constantStride()) == 1)) && (loop.loopBegin().isMainLoop() || loop.loopBegin().isSimpleLoop())) {
NodeIterable<GuardNode> guards = loop.whole().nodes().filter(GuardNode.class);
if (LoopPredicationMainPath.getValue(graph.getOptions())) {
// C2 only applies loop predication to guards dominating the
// backedge.
// The following logic emulates that behavior.
final NodeIterable<LoopEndNode> loopEndNodes = loop.loopBegin().loopEnds();
final Block end = data.getCFG().commonDominatorFor(loopEndNodes);
guards = guards.filter(guard -> {
final ValueNode anchor = ((GuardNode) guard).getAnchor().asNode();
final Block anchorBlock = data.getCFG().getNodeToBlock().get(anchor);
return AbstractControlFlowGraph.dominates(anchorBlock, end);
});
}
final AbstractBeginNode body = loop.counted().getBody();
final Block bodyBlock = cfg.getNodeToBlock().get(body);
for (GuardNode guard : guards) {
final AnchoringNode anchor = guard.getAnchor();
final Block anchorBlock = cfg.getNodeToBlock().get(anchor.asNode());
// for inverted loop the anchor can dominate the body
if (!inverted) {
if (!AbstractControlFlowGraph.dominates(bodyBlock, anchorBlock)) {
continue;
}
}
processGuard(loop, guard);
}
}
}
}
} catch (Throwable t) {
throw debug.handle(t);
}
}
}
Aggregations