# HG changeset patch # User Doug Simon # Date 1367489981 -7200 # Node ID 9384ec90632be792e5b5526aad55711a5c6b1acd # Parent 56dc7fe83f8a74c2fe4f12220e053ca98fc1134c# Parent 82b2a2c652bb7c8694e6cb1a4a97a61769e6676a Merge. diff -r 56dc7fe83f8a -r 9384ec90632b graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/EliminateNestedCheckCastsTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/EliminateNestedCheckCastsTest.java Thu May 02 11:40:07 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/EliminateNestedCheckCastsTest.java Thu May 02 12:19:41 2013 +0200 @@ -62,7 +62,33 @@ @Test public void test2() { - compileSnippet("test2Snippet", 5, 2); + compileSnippet("test2Snippet", 5, 1); + } + + public static long test3Snippet(A1 a1) { + long result = a1.x1; + A2 a2 = (A2) a1; + if (a1.x1 == 42) { + A3 a3 = (A3) a2; + result = a3.x3; + } + return result; + } + + @Test + public void test3() { + compileSnippet("test3Snippet", 2, 2); + } + + public static long test4Snippet(A1 a1, A1 b1) { + A2 a2 = (A2) a1; + A3 b3 = (A3) b1; + return a2.x2 + b3.x3; + } + + @Test + public void test4() { + compileSnippet("test4Snippet", 2, 2); } private StructuredGraph compileSnippet(final String snippet, final int checkcasts, final int afterCanon) { @@ -71,6 +97,7 @@ @Override public StructuredGraph call() throws Exception { StructuredGraph graph = parse(snippet); + Debug.dump(graph, "After parsing: " + snippet); Assert.assertEquals(checkcasts, graph.getNodes().filter(CheckCastNode.class).count()); new CanonicalizerPhase.Instance(runtime(), new Assumptions(false)).apply(graph); Assert.assertEquals(afterCanon, graph.getNodes(CheckCastNode.class).count()); diff -r 56dc7fe83f8a -r 9384ec90632b graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Thu May 02 11:40:07 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java Thu May 02 12:19:41 2013 +0200 @@ -85,10 +85,10 @@ // checkcast. return object(); } - // remove checkcast if the only usage is a more specific checkcast - if (usages().count() == 1) { - CheckCastNode ccn = usages().filter(CheckCastNode.class).first(); - if (ccn != null && ccn.type() != null && type.isAssignableFrom(ccn.type())) { + // remove checkcast if next node is a more specific checkcast + if (next() instanceof CheckCastNode) { + CheckCastNode ccn = (CheckCastNode) next(); + if (ccn != null && ccn.type() != null && this == ccn.object() && type.isAssignableFrom(ccn.type())) { return object(); } }