# HG changeset patch # User Lukas Stadler # Date 1373888219 -7200 # Node ID 9f5a4074e36b282a98c16a1d5962f86f0da173dd # Parent e7c0658c2f25092ba30b7a371d6176417e51be97 test for nullness and disjunctive conditions in ConditionalEliminationPhase diff -r e7c0658c2f25 -r 9f5a4074e36b graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java Mon Jul 15 13:36:41 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java Mon Jul 15 13:36:59 2013 +0200 @@ -22,8 +22,13 @@ */ package com.oracle.graal.compiler.test; +import static org.junit.Assert.*; + import org.junit.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.common.*; /** @@ -89,4 +94,82 @@ test("search", e2, "e3", new Entry("e4")); } + + @SuppressWarnings("unused") + public static int testNullnessSnippet(Object a, Object b) { + if (a == null) { + if (a == b) { + if (b == null) { + return 1; + } else { + return -2; + } + } else { + if (b == null) { + return 3; + } else { + return 4; + } + } + } else { + if (a == b) { + if (b == null) { + return -5; + } else { + return 6; + } + } else { + if (b == null) { + return 7; + } else { + return 8; + } + } + } + } + + @Test + public void testNullness() { + test("testNullnessSnippet", null, null); + test("testNullnessSnippet", null, new Object()); + test("testNullnessSnippet", new Object(), null); + test("testNullnessSnippet", new Object(), new Object()); + + StructuredGraph graph = parse("testNullnessSnippet"); + new ConditionalEliminationPhase(runtime()).apply(graph); + new CanonicalizerPhase.Instance(runtime(), null, true).apply(graph); + for (ConstantNode constant : graph.getNodes().filter(ConstantNode.class)) { + assertTrue("unexpected constant: " + constant, constant.asConstant().isNull() || constant.asConstant().asInt() > 0); + } + } + + @SuppressWarnings("unused") + public static int testDisjunctionSnippet(Object a) { + if (a instanceof Integer) { + if (a == null) { + return -1; + } else { + return 2; + } + } else { + return 3; + } + } + + @Test + public void testDisjunction() { + StructuredGraph graph = parse("testDisjunctionSnippet"); + new CanonicalizerPhase.Instance(runtime(), null, true).apply(graph); + IfNode ifNode = (IfNode) graph.start().next(); + InstanceOfNode instanceOf = (InstanceOfNode) ifNode.condition(); + LogicDisjunctionNode disjunction = graph.unique(new LogicDisjunctionNode(graph.unique(new IsNullNode(graph.getLocal(0))), instanceOf)); + ifNode.setCondition(disjunction); + ifNode.negate(disjunction); + new CanonicalizerPhase.Instance(runtime(), null, true).apply(graph); + new ConditionalEliminationPhase(runtime()).apply(graph); + new CanonicalizerPhase.Instance(runtime(), null, true).apply(graph); + for (ConstantNode constant : graph.getNodes().filter(ConstantNode.class)) { + assertTrue("unexpected constant: " + constant, constant.asConstant().isNull() || constant.asConstant().asInt() > 0); + } + } }