changeset 16496:b40984b06157

make PhiNode.singleValue behave correctly for null values (in guard phis)
author Lukas Stadler <lukas.stadler@oracle.com>
date Fri, 11 Jul 2014 16:41:14 +0200
parents 569b90d12edb
children c087cb67ba6d
files graal/com.oracle.graal.loop/src/com/oracle/graal/loop/InductionVariables.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValuePhiNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java
diffstat 4 files changed, 28 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/InductionVariables.java	Fri Jul 11 14:27:06 2014 +0200
+++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/InductionVariables.java	Fri Jul 11 16:41:14 2014 +0200
@@ -51,7 +51,7 @@
         AbstractEndNode forwardEnd = loopBegin.forwardEnd();
         for (PhiNode phi : loopBegin.phis()) {
             ValueNode backValue = phi.singleBackValue();
-            if (backValue == null) {
+            if (backValue == PhiNode.NO_VALUE) {
                 continue;
             }
             ValueNode stride = addSub(backValue, phi);
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java	Fri Jul 11 14:27:06 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java	Fri Jul 11 16:41:14 2014 +0200
@@ -22,6 +22,8 @@
  */
 package com.oracle.graal.nodes;
 
+import java.util.*;
+
 import com.oracle.graal.compiler.common.type.*;
 import com.oracle.graal.graph.*;
 import com.oracle.graal.graph.spi.*;
@@ -135,39 +137,42 @@
         values().remove(index);
     }
 
+    public static final ValueNode NO_VALUE = new ValueNode(null) {
+        // empty dummy class
+    };
+
     public ValueNode singleValue() {
-        ValueNode differentValue = null;
-        for (ValueNode n : values()) {
-            assert n != null : "Must have input value!";
-            if (n != this) {
-                if (differentValue == null) {
-                    differentValue = n;
-                } else if (differentValue != n) {
-                    return null;
+        Iterator<ValueNode> iterator = values().iterator();
+        ValueNode singleValue = iterator.next();
+        while (iterator.hasNext()) {
+            ValueNode value = iterator.next();
+            if (value != this) {
+                if (value != singleValue) {
+                    return NO_VALUE;
                 }
             }
         }
-        return differentValue;
+        return singleValue;
     }
 
     public ValueNode singleBackValue() {
         assert merge() instanceof LoopBeginNode;
-        ValueNode differentValue = null;
-        for (ValueNode n : values().subList(merge().forwardEndCount(), values().size())) {
-            if (differentValue == null) {
-                differentValue = n;
-            } else if (differentValue != n) {
-                return null;
+        Iterator<ValueNode> iterator = values().iterator();
+        iterator.next();
+        ValueNode singleValue = iterator.next();
+        while (iterator.hasNext()) {
+            if (iterator.next() != singleValue) {
+                return NO_VALUE;
             }
         }
-        return differentValue;
+        return singleValue;
     }
 
     @Override
     public void simplify(SimplifierTool tool) {
         ValueNode singleValue = singleValue();
 
-        if (singleValue != null) {
+        if (singleValue != NO_VALUE) {
             for (Node node : usages().snapshot()) {
                 if (node instanceof ProxyNode && ((ProxyNode) node).proxyPoint() instanceof LoopExitNode && ((LoopExitNode) ((ProxyNode) node).proxyPoint()).loopBegin() == merge) {
                     tool.addToWorkList(node.usages());
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValuePhiNode.java	Fri Jul 11 14:27:06 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ValuePhiNode.java	Fri Jul 11 16:41:14 2014 +0200
@@ -24,14 +24,13 @@
 
 import com.oracle.graal.compiler.common.type.*;
 import com.oracle.graal.graph.*;
-import com.oracle.graal.graph.spi.*;
 import com.oracle.graal.nodes.type.*;
 
 /**
  * Value {@link PhiNode}s merge data flow values at control flow merges.
  */
 @NodeInfo(nameTemplate = "ValuePhi({i#values})")
-public class ValuePhiNode extends PhiNode implements Simplifiable {
+public class ValuePhiNode extends PhiNode {
 
     @Input final NodeInputList<ValueNode> values;
 
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Fri Jul 11 14:27:06 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Fri Jul 11 16:41:14 2014 +0200
@@ -174,7 +174,7 @@
         }
 
         ValueNode singleValue = phiNode.singleValue();
-        if (singleValue != null) {
+        if (singleValue != PhiNode.NO_VALUE) {
             Collection<PhiNode> phiUsages = phiNode.usages().filter(PhiNode.class).snapshot();
             Collection<ProxyNode> proxyUsages = phiNode.usages().filter(ProxyNode.class).snapshot();
             phiNode.graph().replaceFloating(phiNode, singleValue);
@@ -343,6 +343,9 @@
                 v = ((ValueProxy) v).getOriginalNode();
             } else if (v instanceof PhiNode) {
                 v = ((PhiNode) v).singleValue();
+                if (v == PhiNode.NO_VALUE) {
+                    v = null;
+                }
             } else {
                 break;
             }