changeset 23170:cce1287c1778

Perform GVN in the canonicalizer also on leaf nodes.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 13 Dec 2015 23:10:05 +0100
parents db2df49e2245
children 827a777e8dc4
files graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/EffectsPhase.java
diffstat 3 files changed, 6 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Sun Dec 13 17:11:44 2015 +0100
+++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Graph.java	Sun Dec 13 23:10:05 2015 +0100
@@ -591,6 +591,10 @@
         return result;
     }
 
+    /**
+     * Returns a possible duplicate for the given node in the graph or {@code null} if no such
+     * duplicate exists.
+     */
     @SuppressWarnings("unchecked")
     public <T extends Node> T findDuplicate(T node) {
         NodeClass<?> nodeClass = node.getNodeClass();
@@ -598,7 +602,7 @@
         if (nodeClass.isLeafNode()) {
             // Leaf node: look up in cache
             Node cachedNode = findNodeInCache(node);
-            if (cachedNode != null) {
+            if (cachedNode != null && cachedNode != node) {
                 return (T) cachedNode;
             } else {
                 return null;
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java	Sun Dec 13 17:11:44 2015 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java	Sun Dec 13 23:10:05 2015 +0100
@@ -237,7 +237,7 @@
         }
 
         public boolean tryGlobalValueNumbering(Node node, NodeClass<?> nodeClass) {
-            if (nodeClass.valueNumberable() && !nodeClass.isLeafNode()) {
+            if (nodeClass.valueNumberable()) {
                 Node newNode = node.graph().findDuplicate(node);
                 if (newNode != null) {
                     assert !(node instanceof FixedNode || newNode instanceof FixedNode);
@@ -248,24 +248,9 @@
                     return true;
                 }
             }
-            assert assertLeafGVN(node, nodeClass);
             return false;
         }
 
-        /**
-         * Ensures that leaf nodes have already been GVN'ed. This is handled automatically by the
-         * various {@code add} methods in {@link Graph} but uses of
-         * {@link Graph#addWithoutUnique(Node)} and {@link Graph#addWithoutUniqueWithInputs(Node)}
-         * will leave non-unique copies floating around which defeats GVN of users of those nodes.
-         */
-        private boolean assertLeafGVN(Node node, NodeClass<?> nodeClass) {
-            if (node.isAlive() && nodeClass.valueNumberable() && nodeClass.isLeafNode()) {
-                Node newNode = node.graph().findDuplicate(node);
-                return (newNode == null || newNode == node);
-            }
-            return true;
-        }
-
         private AutoCloseable getCanonicalizeableContractAssertion(Node node) {
             boolean needsAssertion = false;
             assert (needsAssertion = true) == true;
--- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/EffectsPhase.java	Sun Dec 13 17:11:44 2015 +0100
+++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/EffectsPhase.java	Sun Dec 13 23:10:05 2015 +0100
@@ -122,27 +122,6 @@
     }
 
     protected void postIteration(final StructuredGraph graph, final PhaseContextT context, Set<Node> changedNodes) {
-        /*
-         * The nodes were added without uniqueing them first so GVN the leaf nodes now. The normal
-         * CanonicalizerPhase will GVN non-leaf value numberable nodes.
-         */
-        for (Node node : changedNodes) {
-            if (node.isAlive() && node.getNodeClass().valueNumberable() && node.getNodeClass().isLeafNode()) {
-                Node duplicate = graph.findDuplicate(node);
-                if (duplicate != node) {
-                    if (duplicate == null) {
-                        /*
-                         * There's no version of this constant in the leaf node cache so create a
-                         * copy to add it to the table.
-                         */
-                        duplicate = node.copyWithInputs();
-                        assert duplicate == graph.findDuplicate(duplicate);
-                    }
-                    node.replaceAtUsages(duplicate);
-                    node.safeDelete();
-                }
-            }
-        }
         if (canonicalizer != null) {
             canonicalizer.applyIncremental(graph, context, changedNodes);
         }