# HG changeset patch # User Lukas Stadler # Date 1374502735 -7200 # Node ID 020f63bfd781a5e1b409e514bdc27d0961ec766f # Parent e43eb9fe98e5945c4096c3c19cf57ba5aa1ac26f fix merging of types in ConditionalEliminationPhase bug reported by Miguel Garcia diff -r e43eb9fe98e5 -r 020f63bfd781 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 22 16:04:43 2013 +0200 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java Mon Jul 22 16:18:55 2013 +0200 @@ -39,6 +39,8 @@ */ public class ConditionalEliminationTest extends GraalCompilerTest { + public static Object field; + static class Entry { final String name; @@ -196,4 +198,34 @@ assertEquals(InvokeKind.Special, ((MethodCallTargetNode) invoke.callTarget()).invokeKind()); } + public static void testTypeMergingSnippet(Object o, boolean b) { + if (b) { + if (!(o instanceof Double)) { + return; + } + } else { + if (!(o instanceof Integer)) { + return; + } + } + + /* + * For this test the conditional elimination has to correctly merge the type information it + * has about o, so that it can remove the check on Number. + */ + if (!(o instanceof Number)) { + field = o; + } + } + + @Test + public void testTypeMerging() { + StructuredGraph graph = parse("testTypeMergingSnippet"); + new CanonicalizerPhase.Instance(runtime(), null, true).apply(graph); + new ConditionalEliminationPhase(runtime()).apply(graph); + new CanonicalizerPhase.Instance(runtime(), null, true).apply(graph); + + assertEquals(0, graph.getNodes().filter(StoreFieldNode.class).count()); + } + } diff -r e43eb9fe98e5 -r 020f63bfd781 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Mon Jul 22 16:04:43 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Mon Jul 22 16:18:55 2013 +0200 @@ -114,7 +114,7 @@ break; } } - if (type == null && type != node.objectStamp().type()) { + if (type != null && type != node.objectStamp().type()) { newKnownTypes.put(node, type); } }