Skip to content

Commit 15c39e8

Browse files
committed
[GR-59001][GR-59002][GR-61452] Safepoint changes.
PullRequest: graal/19135
2 parents bbdf41b + 23bcab5 commit 15c39e8

17 files changed

+435
-120
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/CountedLoopMaxTripCountPiTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ int ascendingSnippet(int start, int limit) {
5454
for (int i = start; GraalDirectives.injectIterationCount(101, i < limit); i++) {
5555
GraalDirectives.sideEffect(i);
5656
sum += i;
57+
GraalDirectives.neverStripMine();
5758
}
5859
return sum + maxTripCount;
5960
}
@@ -64,6 +65,7 @@ int descendingSnippet(int start, int limit) {
6465
for (int i = start; GraalDirectives.injectIterationCount(102, i >= limit); i--) {
6566
GraalDirectives.sideEffect(i);
6667
sum += i;
68+
GraalDirectives.neverStripMine();
6769
}
6870
return sum + maxTripCount;
6971
}
@@ -76,9 +78,12 @@ int descendingSnippet(int start, int limit) {
7678
void checkGraph(StructuredGraph graph, LoopsData loops) {
7779
loops.detectCountedLoops();
7880
for (Loop loop : loops.loops()) {
81+
if (loop.loopBegin().isStripMinedOuter()) {
82+
continue;
83+
}
7984
// max trip count can only be used if a loop does not overflow
80-
loop.counted().createOverFlowGuard();
8185
Assert.assertTrue("expect all loops to be counted", loop.isCounted());
86+
loop.counted().createOverFlowGuard();
8287
ValueNode maxTripCountNode = loop.counted().maxTripCountNode();
8388
Assert.assertTrue("expect a PiNode for the guarded maxTripCount, got: " + maxTripCountNode, maxTripCountNode instanceof PiNode);
8489
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/LoopSafepointStateVerificationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public Optional<NotApplicable> notApplicableTo(GraphState graphState) {
9999
@Override
100100
protected void run(StructuredGraph graph, HighTierContext context) {
101101
for (LoopBeginNode lb : graph.getNodes(LoopBeginNode.TYPE)) {
102-
lb.disableSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
103-
lb.disableGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
102+
lb.setLoopEndSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
103+
lb.setGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
104104
}
105105
}
106106

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/deopt/MonitorDeoptTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ private static LoopBeginNode findFirstLoop(StructuredGraph graph) {
181181
*/
182182
private static void removeLoopSafepoint(StructuredGraph graph) {
183183
LoopBeginNode loopBegin = findFirstLoop(graph);
184-
loopBegin.disableSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
184+
loopBegin.setLoopEndSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
185185
}
186186

187187
@Test

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/loop/test/LoopFragmentTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ protected void checkMidTierGraph(StructuredGraph graph) {
5959
}
6060
NodeIterable<LoopBeginNode> loops = graph.getNodes().filter(LoopBeginNode.class);
6161
// Loops might be optimizable after partial unrolling
62-
if (!loops.isEmpty()) {
63-
for (LoopBeginNode loop : loops) {
64-
if (loop.isMainLoop()) {
65-
return;
66-
}
62+
boolean seenLoop = false;
63+
for (LoopBeginNode loop : loops) {
64+
if (loop.isStripMinedOuter()) {
65+
continue;
6766
}
67+
seenLoop = true;
68+
if (loop.isMainLoop()) {
69+
return;
70+
}
71+
}
72+
if (seenLoop) {
6873
fail("expected a main loop");
6974
}
7075
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/java/BytecodeParser.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3910,9 +3910,9 @@ private LoopBeginNode appendLoopBegin(FixedWithNextNode fixedWithNext, int start
39103910
EndNode preLoopEnd = graph.add(new EndNode());
39113911
LoopBeginNode loopBegin = graph.add(new LoopBeginNode());
39123912
if (disableLoopSafepoint()) {
3913-
loopBegin.disableSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
3914-
loopBegin.disableGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
3915-
loopBegin.disableLoopExitSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
3913+
loopBegin.setLoopEndSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
3914+
loopBegin.setGuestSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
3915+
loopBegin.setLoopExitSafepoint(SafepointState.MUST_NEVER_SAFEPOINT);
39163916
}
39173917
fixedWithNext.setNext(preLoopEnd);
39183918
// Add the single non-loop predecessor of the loop header.

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import jdk.graal.compiler.debug.DebugContext;
3333
import jdk.graal.compiler.graph.Graph;
34+
import jdk.graal.compiler.graph.NodeBitMap;
35+
import jdk.graal.compiler.loop.phases.LoopTransformations.PreMainPostResult;
3436
import jdk.graal.compiler.nodes.GraphState;
3537
import jdk.graal.compiler.nodes.GraphState.StageFlag;
3638
import jdk.graal.compiler.nodes.LoopBeginNode;
@@ -56,7 +58,8 @@ private void unroll(StructuredGraph graph, CoreProviders context) {
5658
EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener();
5759
boolean changed = true;
5860
EconomicMap<LoopBeginNode, OpaqueNode> opaqueUnrolledStrides = null;
59-
boolean prePostInserted = false;
61+
NodeBitMap newMainLoops = null;
62+
6063
while (changed) {
6164
changed = false;
6265
try (Graph.NodeEventScope nes = graph.trackNodeEvents(listener)) {
@@ -72,10 +75,13 @@ private void unroll(StructuredGraph graph, CoreProviders context) {
7275
// First perform the pre/post transformation and do the partial
7376
// unroll when we come around again.
7477
LoopUtility.preserveCounterStampsForDivAfterUnroll(loop);
75-
LoopTransformations.insertPrePostLoops(loop);
76-
prePostInserted = true;
78+
PreMainPostResult res = LoopTransformations.insertPrePostLoops(loop);
79+
if (newMainLoops == null) {
80+
newMainLoops = graph.createNodeBitMap();
81+
}
82+
newMainLoops.markAndGrow(res.getMainLoop());
7783
changed = true;
78-
} else if (prePostInserted) {
84+
} else if (newMainLoops != null && newMainLoops.isMarkedAndGrow(loop.loopBegin())) {
7985
if (opaqueUnrolledStrides == null) {
8086
opaqueUnrolledStrides = EconomicMap.create(Equivalence.IDENTITY);
8187
}
@@ -94,7 +100,7 @@ private void unroll(StructuredGraph graph, CoreProviders context) {
94100
listener.getNodes().clear();
95101
}
96102

97-
assert !prePostInserted || checkCounted(graph, context.getLoopsDataProvider(), mark);
103+
assert newMainLoops == null || checkCounted(graph, context.getLoopsDataProvider(), mark);
98104
}
99105
}
100106
if (opaqueUnrolledStrides != null) {

0 commit comments

Comments
 (0)