changeset 9543:f8a5f7f7d0bd

CheckCastNode: eliminate the other way around and replace the previous node with a more specific node regarding its type
author Bernhard Urban <bernhard.urban@jku.at>
date Fri, 03 May 2013 15:05:07 +0200
parents 8a6bd04d9510
children 5bf09c5cd2e6
files graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/EliminateNestedCheckCastsTest.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java
diffstat 2 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/EliminateNestedCheckCastsTest.java	Fri May 03 15:29:26 2013 +0200
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/EliminateNestedCheckCastsTest.java	Fri May 03 15:05:07 2013 +0200
@@ -26,7 +26,7 @@
 
 import junit.framework.Assert;
 
-import org.junit.*;
+import org.junit.Test;
 
 import com.oracle.graal.api.code.*;
 import com.oracle.graal.debug.*;
@@ -99,7 +99,6 @@
         return sum + a3.x3;
     }
 
-    @Ignore
     @Test
     public void test5() {
         StructuredGraph graph = compileSnippet("test5Snippet", 2, 1);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java	Fri May 03 15:29:26 2013 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CheckCastNode.java	Fri May 03 15:05:07 2013 +0200
@@ -85,11 +85,15 @@
             // checkcast.
             return object();
         }
+
         // 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();
+        if (predecessor() instanceof CheckCastNode) {
+            CheckCastNode ccn = (CheckCastNode) predecessor();
+            if (ccn != null && ccn.type != null && ccn == object && ccn.forStoreCheck == forStoreCheck && ccn.type.isAssignableFrom(type)) {
+                StructuredGraph graph = (StructuredGraph) ccn.graph();
+                CheckCastNode newccn = graph.add(new CheckCastNode(type, ccn.object, ccn.profile, ccn.forStoreCheck));
+                graph.replaceFixedWithFixed(ccn, newccn);
+                return newccn;
             }
         }