Skip to content

Commit b280147

Browse files
committed
[GR-48652] [GR-48664] Read elimination: only kill mutable locations when encountering ANY.
PullRequest: graal/15612
2 parents c1b45e4 + aa0b8b2 commit b280147

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/core/phases/LowTier.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,21 @@ static class Options {
5757

5858
}
5959

60+
private final CanonicalizerPhase canonicalizerWithoutGVN;
61+
private final CanonicalizerPhase canonicalizerWithGVN;
62+
6063
@SuppressWarnings("this-escape")
6164
public LowTier(OptionValues options) {
62-
CanonicalizerPhase canonicalizer = CanonicalizerPhase.create();
63-
CanonicalizerPhase canonicalizerWithoutGVN = canonicalizer.copyWithoutGVN();
65+
this.canonicalizerWithGVN = CanonicalizerPhase.create();
66+
this.canonicalizerWithoutGVN = canonicalizerWithGVN.copyWithoutGVN();
6467

6568
if (Options.ProfileCompiledMethods.getValue(options)) {
6669
appendPhase(new ProfileCompiledMethodsPhase());
6770
}
6871

69-
appendPhase(new LowTierLoweringPhase(canonicalizer));
72+
appendPhase(new LowTierLoweringPhase(canonicalizerWithGVN));
7073

71-
appendPhase(new ExpandLogicPhase(canonicalizer));
74+
appendPhase(new ExpandLogicPhase(canonicalizerWithGVN));
7275

7376
appendPhase(new FixReadsPhase(true,
7477
new SchedulePhase(GraalOptions.StressTestEarlyReads.getValue(options) ? SchedulingStrategy.EARLIEST : SchedulingStrategy.LATEST_OUT_OF_LOOPS_IMPLICIT_NULL_CHECKS)));
@@ -92,4 +95,12 @@ public LowTier(OptionValues options) {
9295

9396
appendPhase(new SchedulePhase(SchedulePhase.SchedulingStrategy.LATEST_OUT_OF_LOOPS));
9497
}
98+
99+
public final CanonicalizerPhase getCanonicalizerWithoutGVN() {
100+
return canonicalizerWithoutGVN;
101+
}
102+
103+
public final CanonicalizerPhase getCanonicalizer() {
104+
return canonicalizerWithGVN;
105+
}
95106
}

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/nodes/GraphState.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ public enum StageFlag {
625625
VECTOR_LOWERING,
626626
EXPAND_LOGIC,
627627
FIXED_READS,
628+
PARTIAL_REDUNDANCY_SCHEDULE,
628629
ADDRESS_LOWERING,
629630
FINAL_CANONICALIZATION,
630631
TARGET_VECTOR_LOWERING,

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/phases/common/CanonicalizerPhase.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ protected CanonicalizerPhase(CustomSimplification customSimplification, EnumSet<
156156
this.features = features;
157157
}
158158

159+
public EnumSet<CanonicalizerFeature> getFeatures() {
160+
return features;
161+
}
162+
159163
public CanonicalizerPhase copyWithCustomSimplification(CustomSimplification newSimplification) {
160164
return new CanonicalizerPhase(newSimplification, features);
161165
}
@@ -508,7 +512,7 @@ private boolean processNode(Node node, Tool tool) {
508512
return false;
509513
}
510514

511-
public boolean tryGlobalValueNumbering(Node node, NodeClass<?> nodeClass) {
515+
public static boolean gvn(Node node, NodeClass<?> nodeClass) {
512516
if (nodeClass.valueNumberable()) {
513517
Node newNode = node.graph().findDuplicate(node);
514518
if (newNode != null) {
@@ -522,6 +526,13 @@ public boolean tryGlobalValueNumbering(Node node, NodeClass<?> nodeClass) {
522526
return false;
523527
}
524528

529+
public boolean tryGlobalValueNumbering(Node node, NodeClass<?> nodeClass) {
530+
assert ((StructuredGraph) node.graph()).getGraphState().isBeforeStage(StageFlag.PARTIAL_REDUNDANCY_SCHEDULE) : "GVN must not occur after expanding partially redundant nodes, trying to gvn " +
531+
node +
532+
" for graph " + node.graph();
533+
return gvn(node, nodeClass);
534+
}
535+
525536
private static AutoCloseable getCanonicalizeableContractAssertion(Node node) {
526537
boolean needsAssertion = false;
527538
assert (needsAssertion = true) == true;

compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/virtual/phases/ea/ReadEliminationBlockState.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,16 @@ public ValueNode getCacheEntry(CacheEntry<?> identifier) {
193193

194194
public void killReadCache(LocationIdentity identity, ValueNode index, ValueNode array) {
195195
if (identity.isAny()) {
196-
// ANY aliases with every other location
197-
readCache.clear();
196+
/**
197+
* Kill all mutable locations.
198+
*/
199+
Iterator<CacheEntry<?>> iterator = readCache.getKeys().iterator();
200+
while (iterator.hasNext()) {
201+
CacheEntry<?> entry = iterator.next();
202+
if (entry.getIdentity().isMutable()) {
203+
iterator.remove();
204+
}
205+
}
198206
return;
199207
}
200208
Iterator<CacheEntry<?>> iterator = readCache.getKeys().iterator();

0 commit comments

Comments
 (0)