Skip to content

Commit

Permalink
EarlyReadElimination: Properly clone the dead flag of states
Browse files Browse the repository at this point in the history
  • Loading branch information
davleopo committed Oct 11, 2019
1 parent ac3a21a commit 1390e2d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import java.util.List;

import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.nodes.IfNode;
import org.graalvm.compiler.nodes.LogicConstantNode;
import org.graalvm.compiler.nodes.ProxyNode;
import org.graalvm.compiler.nodes.ReturnNode;
import org.graalvm.compiler.nodes.StructuredGraph;
Expand All @@ -47,6 +50,50 @@ public class EarlyReadEliminationTest extends GraalCompilerTest {

public static Object staticField;

static void cfgSnippet() {
if (staticField != null) {
staticField = 12;
if (staticField != null) {
staticField = 12;
}
if (staticField != null) {
staticField = 12;
}
if (staticField != null) {
staticField = 12;
}
if (staticField != null) {
staticField = 12;
}
} else {
if (staticField != null) {
staticField = 12;
} else {
if (staticField != null) {
staticField = 12;
}
}
}
}

@Test
public void testDeadBranches() {
StructuredGraph graph = parseEager(getResolvedJavaMethod("cfgSnippet"), AllowAssumptions.NO);
HighTierContext context = getDefaultHighTierContext();
int index = 0;
boolean[] conditions = new boolean[]{true, false, false, true, true, true, false};
/*
* Create a graph with "dead" branches in the beginning.
*/
for (Node n : graph.getNodes()) {
if (n instanceof IfNode) {
IfNode ifNode = (IfNode) n;
ifNode.setCondition(LogicConstantNode.forBoolean(conditions[index++], graph));
}
}
new EarlyReadEliminationPhase(new CanonicalizerPhase()).apply(graph, context);
}

public static class TestObject {

public int x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public ReadEliminationBlockState() {
}

public ReadEliminationBlockState(ReadEliminationBlockState other) {
super(other);
readCache = EconomicMap.create(Equivalence.DEFAULT, other.readCache);
}

Expand Down

0 comments on commit 1390e2d

Please sign in to comment.