changeset 10841:020f63bfd781

fix merging of types in ConditionalEliminationPhase bug reported by Miguel Garcia <miguelalfredo.garcia@epfl.ch>
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 22 Jul 2013 16:18:55 +0200
parents e43eb9fe98e5
children 63c3d7b5edd9
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ConditionalEliminationTest.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java
diffstat 2 files changed, 33 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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());
+    }
+
 }
--- 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);
                 }
             }