# HG changeset patch # User Bernhard Urban # Date 1365168262 -7200 # Node ID ce271e0d03726cc95f4ee03345a9b23c0006e100 # Parent 3bbad4ec6510371ad14e9ce315f3314901acafd2 PiPushable: implementation for IsNullNode diff -r 3bbad4ec6510 -r ce271e0d0372 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java Thu Apr 04 16:03:08 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/PushNodesThroughPiTest.java Fri Apr 05 15:24:22 2013 +0200 @@ -29,8 +29,8 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; -import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.phases.common.*; @@ -50,39 +50,43 @@ B b = (B) a; long ret = b.x; // this can be moved before the checkcast ret += b.y; + // the null-check should be canonicalized with the null-check of the checkcast + ret += b != null ? 100 : 200; return ret; } @Test public void test1() { - test("test1Snippet"); - } - - private void test(final String snippet) { + final String snippet = "test1Snippet"; Debug.scope("PushThroughPi", new DebugDumpScope(snippet), new Runnable() { public void run() { - StructuredGraph graph = parse(snippet); - new LoweringPhase(null, runtime(), new Assumptions(false)).apply(graph); - new CanonicalizerPhase(runtime(), null).apply(graph); - new PushNodesThroughPi().apply(graph); - new CanonicalizerPhase(runtime(), null).apply(graph); + StructuredGraph graph = compileTestSnippet(snippet); - for (Node n : graph.getNodes()) { - if (n instanceof ReadNode) { - ReadNode rn = (ReadNode) n; - Object locId = rn.location().locationIdentity(); - if (locId instanceof ResolvedJavaField) { - ResolvedJavaField field = (ResolvedJavaField) locId; - if (field.getName().equals("x")) { - Assert.assertTrue(rn.object() instanceof LocalNode); - } else { - Assert.assertTrue(rn.object() instanceof UnsafeCastNode); - } + for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) { + Object locId = rn.location().locationIdentity(); + if (locId instanceof ResolvedJavaField) { + ResolvedJavaField field = (ResolvedJavaField) locId; + if (field.getName().equals("x")) { + Assert.assertTrue(rn.object() instanceof LocalNode); + } else { + Assert.assertTrue(rn.object() instanceof UnsafeCastNode); } } } + + Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1); } }); } + + private StructuredGraph compileTestSnippet(final String snippet) { + StructuredGraph graph = parse(snippet); + new LoweringPhase(null, runtime(), replacements, new Assumptions(false)).apply(graph); + new CanonicalizerPhase(runtime(), null).apply(graph); + new PushNodesThroughPi().apply(graph); + new CanonicalizerPhase(runtime(), null).apply(graph); + + return graph; + } } diff -r 3bbad4ec6510 -r ce271e0d0372 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java Thu Apr 04 16:03:08 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IsNullNode.java Fri Apr 05 15:24:22 2013 +0200 @@ -29,7 +29,7 @@ /** * An IsNullNode will be true if the supplied value is null, and false if it is non-null. */ -public final class IsNullNode extends LogicNode implements Canonicalizable, LIRLowerable, Virtualizable { +public final class IsNullNode extends LogicNode implements Canonicalizable, LIRLowerable, Virtualizable, PiPushable { @Input private ValueNode object; @@ -78,4 +78,9 @@ tool.replaceWithValue(LogicConstantNode.contradiction(graph())); } } + + @Override + public void push(PiNode parent) { + replaceFirstInput(parent, parent.object()); + } }