Skip to content

Commit 43d4eb6

Browse files
committed
[GR-58960] Convert deopt to guard: allow disabling reasoning about counted loops.
PullRequest: graal/19811
2 parents c68dbdc + a8da37a commit 43d4eb6

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/loop/phases/ConvertDeoptimizeToGuardPhase.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,15 @@
9292
*/
9393
public class ConvertDeoptimizeToGuardPhase extends PostRunCanonicalizationPhase<CoreProviders> implements RecursivePhase {
9494

95+
private final boolean considerCountedExits;
96+
9597
public ConvertDeoptimizeToGuardPhase(CanonicalizerPhase canonicalizer) {
98+
this(canonicalizer, true);
99+
}
100+
101+
public ConvertDeoptimizeToGuardPhase(CanonicalizerPhase canonicalizer, boolean considerCountedExits) {
96102
super(canonicalizer);
103+
this.considerCountedExits = considerCountedExits;
97104
}
98105

99106
@Override
@@ -116,20 +123,20 @@ protected void run(final StructuredGraph graph, final CoreProviders context) {
116123
continue;
117124
}
118125
try (DebugCloseable closable = d.withNodeSourcePosition()) {
119-
propagateFixed(d, d, context, lazyLoops);
126+
propagateFixed(d, d, context, lazyLoops, considerCountedExits);
120127
}
121128
}
122129
if (context != null) {
123130
for (FixedGuardNode fixedGuard : graph.getNodes(FixedGuardNode.TYPE)) {
124131
try (DebugCloseable closable = fixedGuard.withNodeSourcePosition()) {
125-
trySplitFixedGuard(fixedGuard, context, lazyLoops);
132+
trySplitFixedGuard(fixedGuard, context, lazyLoops, considerCountedExits);
126133
}
127134
}
128135
}
129136
new DeadCodeEliminationPhase(Optional).apply(graph);
130137
}
131138

132-
private static void trySplitFixedGuard(FixedGuardNode fixedGuard, CoreProviders context, LazyValue<LoopsData> lazyLoops) {
139+
private static void trySplitFixedGuard(FixedGuardNode fixedGuard, CoreProviders context, LazyValue<LoopsData> lazyLoops, boolean considerCountedExits) {
133140
LogicNode condition = fixedGuard.condition();
134141
if (condition instanceof CompareNode) {
135142
CompareNode compare = (CompareNode) condition;
@@ -139,14 +146,14 @@ private static void trySplitFixedGuard(FixedGuardNode fixedGuard, CoreProviders
139146
ValueNode y = compare.getY();
140147
ValuePhiNode yPhi = (y instanceof ValuePhiNode) ? (ValuePhiNode) y : null;
141148
if (y instanceof ConstantNode || yPhi != null) {
142-
processFixedGuardAndPhis(fixedGuard, context, compare, x, xPhi, y, yPhi, lazyLoops);
149+
processFixedGuardAndPhis(fixedGuard, context, compare, x, xPhi, y, yPhi, lazyLoops, considerCountedExits);
143150
}
144151
}
145152
}
146153
}
147154

148155
private static void processFixedGuardAndPhis(FixedGuardNode fixedGuard, CoreProviders context, CompareNode compare, ValueNode x, ValuePhiNode xPhi, ValueNode y, ValuePhiNode yPhi,
149-
LazyValue<LoopsData> lazyLoops) {
156+
LazyValue<LoopsData> lazyLoops, boolean considerCountedExits) {
150157
AbstractBeginNode pred = AbstractBeginNode.prevBegin(fixedGuard);
151158
if (pred instanceof AbstractMergeNode) {
152159
AbstractMergeNode merge = (AbstractMergeNode) pred;
@@ -157,13 +164,13 @@ private static void processFixedGuardAndPhis(FixedGuardNode fixedGuard, CoreProv
157164
return;
158165
}
159166

160-
processFixedGuardAndMerge(fixedGuard, context, compare, x, xPhi, y, yPhi, merge, lazyLoops);
167+
processFixedGuardAndMerge(fixedGuard, context, compare, x, xPhi, y, yPhi, merge, lazyLoops, considerCountedExits);
161168
}
162169
}
163170

164171
@SuppressWarnings("try")
165172
private static void processFixedGuardAndMerge(FixedGuardNode fixedGuard, CoreProviders context, CompareNode compare, ValueNode x, ValuePhiNode xPhi, ValueNode y, ValuePhiNode yPhi,
166-
AbstractMergeNode merge, LazyValue<LoopsData> lazyLoops) {
173+
AbstractMergeNode merge, LazyValue<LoopsData> lazyLoops, boolean considerCountedExits) {
167174
List<EndNode> mergePredecessors = merge.cfgPredecessors().snapshot();
168175
for (AbstractEndNode mergePredecessor : mergePredecessors) {
169176
if (!mergePredecessor.isAlive()) {
@@ -186,15 +193,15 @@ private static void processFixedGuardAndMerge(FixedGuardNode fixedGuard, CorePro
186193
TriState compareResult = compare.condition().foldCondition(compareStamp, xs, ys, context.getConstantReflection(), compare.unorderedIsTrue());
187194
if (compareResult.isKnown() && compareResult.toBoolean() == fixedGuard.isNegated()) {
188195
try (DebugCloseable position = fixedGuard.withNodeSourcePosition()) {
189-
propagateFixed(mergePredecessor, fixedGuard, context, lazyLoops);
196+
propagateFixed(mergePredecessor, fixedGuard, context, lazyLoops, considerCountedExits);
190197
}
191198
}
192199
}
193200
}
194201
}
195202

196203
@SuppressWarnings("try")
197-
public static void propagateFixed(FixedNode from, StaticDeoptimizingNode deopt, CoreProviders providers, LazyValue<LoopsData> lazyLoops) {
204+
public static void propagateFixed(FixedNode from, StaticDeoptimizingNode deopt, CoreProviders providers, LazyValue<LoopsData> lazyLoops, boolean considerCountedExits) {
198205
Node current = from;
199206
while (current != null) {
200207
if (GraalOptions.GuardPriorities.getValue(from.getOptions()) && current instanceof FixedGuardNode) {
@@ -209,16 +216,16 @@ public static void propagateFixed(FixedNode from, StaticDeoptimizingNode deopt,
209216
FixedNode next = mergeNode.next();
210217
while (mergeNode.isAlive()) {
211218
AbstractEndNode end = mergeNode.forwardEnds().first();
212-
propagateFixed(end, deopt, providers, lazyLoops);
219+
propagateFixed(end, deopt, providers, lazyLoops, considerCountedExits);
213220
}
214221
if (next.isAlive()) {
215-
propagateFixed(next, deopt, providers, lazyLoops);
222+
propagateFixed(next, deopt, providers, lazyLoops, considerCountedExits);
216223
}
217224
return;
218225
} else if (current.predecessor() instanceof IfNode) {
219226
AbstractBeginNode begin = (AbstractBeginNode) current;
220227
IfNode ifNode = (IfNode) current.predecessor();
221-
if (isOsrLoopExit(begin) || isCountedLoopExit(ifNode, lazyLoops)) {
228+
if (isOsrLoopExit(begin) || (considerCountedExits && isCountedLoopExit(ifNode, lazyLoops))) {
222229
moveAsDeoptAfter(begin, deopt);
223230
} else {
224231
if (begin instanceof LoopExitNode && ifNode.condition() instanceof IntegerEqualsNode) {

0 commit comments

Comments
 (0)