changeset 23060:4e72c50bb9c1

Improve handling of pi nodes that directly follow access nodes.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sun, 22 Nov 2015 19:53:38 +0100
parents 6c5f70cd3ed8
children 0f5b5f94448c
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java
diffstat 2 files changed, 56 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java	Sun Nov 22 19:52:42 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java	Sun Nov 22 19:53:38 2015 +0100
@@ -36,6 +36,9 @@
 import com.oracle.graal.graph.spi.CanonicalizerTool;
 import com.oracle.graal.nodeinfo.NodeInfo;
 import com.oracle.graal.nodes.extended.GuardingNode;
+import com.oracle.graal.nodes.extended.UnsafeLoadNode;
+import com.oracle.graal.nodes.java.LoadFieldNode;
+import com.oracle.graal.nodes.java.LoadIndexedNode;
 import com.oracle.graal.nodes.spi.LIRLowerable;
 import com.oracle.graal.nodes.spi.NodeLIRBuilderTool;
 import com.oracle.graal.nodes.spi.ValueProxy;
@@ -116,19 +119,42 @@
             return this;
         }
         inferStamp();
-        if (stamp().equals(object().stamp())) {
-            return object();
+        ValueNode o = object();
+
+        // The pi node does not give any additional information => skip it.
+        if (stamp().equals(o.stamp())) {
+            return o;
         }
-        if (getGuard() != null) {
-            for (PiNode otherPi : getGuard().asNode().usages().filter(PiNode.class)) {
-                if (object() == otherPi.object() && stamp().equals(otherPi.stamp())) {
-                    /*
-                     * Two PiNodes with the same guard and same result, so return the one with the
-                     * more precise piStamp.
-                     */
-                    Stamp newStamp = piStamp.join(otherPi.piStamp);
-                    if (newStamp.equals(otherPi.piStamp)) {
-                        return otherPi;
+
+        GuardingNode g = getGuard();
+        if (g == null) {
+            // Try to merge the pi node with a load node.
+            if (o instanceof LoadFieldNode) {
+                LoadFieldNode loadFieldNode = (LoadFieldNode) o;
+                loadFieldNode.setStamp(loadFieldNode.stamp().improveWith(this.stamp()));
+                return loadFieldNode;
+            } else if (o instanceof UnsafeLoadNode) {
+                UnsafeLoadNode unsafeLoadNode = (UnsafeLoadNode) o;
+                unsafeLoadNode.setStamp(unsafeLoadNode.stamp().improveWith(this.stamp()));
+                return unsafeLoadNode;
+            } else if (o instanceof LoadIndexedNode) {
+                LoadIndexedNode loadIndexedNode = (LoadIndexedNode) o;
+                loadIndexedNode.setStamp(loadIndexedNode.stamp().improveWith(this.stamp()));
+                return loadIndexedNode;
+            }
+        } else {
+            for (Node n : g.asNode().usages()) {
+                if (n instanceof PiNode) {
+                    PiNode otherPi = (PiNode) n;
+                    if (o == otherPi.object() && stamp().equals(otherPi.stamp())) {
+                        /*
+                         * Two PiNodes with the same guard and same result, so return the one with
+                         * the more precise piStamp.
+                         */
+                        Stamp newStamp = piStamp.join(otherPi.piStamp);
+                        if (newStamp.equals(otherPi.piStamp)) {
+                            return otherPi;
+                        }
                     }
                 }
             }
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java	Sun Nov 22 19:52:42 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java	Sun Nov 22 19:53:38 2015 +0100
@@ -228,7 +228,7 @@
                      * and constant folding could still eliminate the call to bailout(). However, we
                      * also want to stop parsing, since we are sure that we will never need the
                      * graph beyond the bailout point.
-                     * 
+                     *
                      * Therefore, we manually emit the call to bailout, which will be intrinsified
                      * later when intrinsifications can no longer be delayed. The call is followed
                      * by a NeverPartOfCompilationNode, which is a control sink and therefore stops
@@ -398,17 +398,24 @@
                         } else {
                             piStamp = StampFactory.declaredTrusted(javaType, nonNull.asJavaConstant().asInt() != 0);
                         }
-                        LogicNode compareNode = CompareNode.createCompareNode(object.graph(), Condition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection);
-                        boolean skipAnchor = false;
-                        if (compareNode instanceof LogicConstantNode) {
-                            LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode;
-                            if (logicConstantNode.getValue()) {
-                                skipAnchor = true;
+
+                        ConditionAnchorNode valueAnchorNode = null;
+                        if (condition.isConstant() && condition.asJavaConstant().asInt() == 1) {
+                            // Nothing to do.
+                        } else {
+                            boolean skipAnchor = false;
+                            LogicNode compareNode = CompareNode.createCompareNode(object.graph(), Condition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection);
+
+                            if (compareNode instanceof LogicConstantNode) {
+                                LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode;
+                                if (logicConstantNode.getValue()) {
+                                    skipAnchor = true;
+                                }
                             }
-                        }
-                        ConditionAnchorNode valueAnchorNode = null;
-                        if (!skipAnchor) {
-                            valueAnchorNode = b.add(new ConditionAnchorNode(compareNode));
+
+                            if (!skipAnchor) {
+                                valueAnchorNode = b.add(new ConditionAnchorNode(compareNode));
+                            }
                         }
                         b.addPush(JavaKind.Object, new PiNode(object, piStamp, valueAnchorNode));
                     }