changeset 16338:2cc0fea0cff6

fix ReadNode canonicalization for guard-type usages of null-checking reads
author Lukas Stadler <lukas.stadler@oracle.com>
date Tue, 01 Jul 2014 14:57:53 +0200
parents 67f3267a8846
children 6f70e0b85e91
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java graal/com.oracle.graal.word/src/com/oracle/graal/word/nodes/WordCastNode.java
diffstat 2 files changed, 19 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Tue Jul 01 12:14:58 2014 +0200
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java	Tue Jul 01 14:57:53 2014 +0200
@@ -66,10 +66,26 @@
 
     @Override
     public Node canonical(CanonicalizerTool tool) {
+        if (usages().isEmpty()) {
+            GuardingNode guard = getGuard();
+            if (guard != null && !(guard instanceof FixedNode)) {
+                // The guard is necessary even if the read goes away.
+                return new ValueAnchorNode((ValueNode) guard);
+            } else {
+                // Read without usages or guard can be safely removed.
+                return null;
+            }
+        }
         if (object() instanceof PiNode && ((PiNode) object()).getGuard() == getGuard()) {
             return new ReadNode(((PiNode) object()).getOriginalNode(), location(), stamp(), getGuard(), getBarrierType(), getNullCheck(), stateBefore());
         }
-        return canonicalizeRead(this, location(), object(), tool);
+        if (!getNullCheck()) {
+            return canonicalizeRead(this, location(), object(), tool);
+        } else {
+            // if this read is a null check, then replacing it with the value is incorrect for
+            // guard-type usages
+            return this;
+        }
     }
 
     @Override
@@ -84,16 +100,6 @@
 
     public static ValueNode canonicalizeRead(ValueNode read, LocationNode location, ValueNode object, CanonicalizerTool tool) {
         MetaAccessProvider metaAccess = tool.getMetaAccess();
-        if (read.usages().isEmpty()) {
-            GuardingNode guard = ((Access) read).getGuard();
-            if (guard != null && !(guard instanceof FixedNode)) {
-                // The guard is necessary even if the read goes away.
-                return new ValueAnchorNode((ValueNode) guard);
-            } else {
-                // Read without usages or guard can be safely removed.
-                return null;
-            }
-        }
         if (tool.canonicalizeReads()) {
             if (metaAccess != null && object != null && object.isConstant()) {
                 if ((location.getLocationIdentity() == LocationIdentity.FINAL_LOCATION || location.getLocationIdentity() == LocationIdentity.ARRAY_LENGTH_LOCATION) &&
--- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/nodes/WordCastNode.java	Tue Jul 01 12:14:58 2014 +0200
+++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/nodes/WordCastNode.java	Tue Jul 01 14:57:53 2014 +0200
@@ -36,6 +36,8 @@
  */
 public final class WordCastNode extends FixedWithNextNode implements LIRLowerable, Canonicalizable {
 
+    @Input private ValueNode input;
+
     public static WordCastNode wordToObject(ValueNode input, Kind wordKind) {
         assert input.getKind() == wordKind;
         return new WordCastNode(StampFactory.object(), input);
@@ -46,8 +48,6 @@
         return new WordCastNode(StampFactory.forKind(wordKind), input);
     }
 
-    @Input private ValueNode input;
-
     private WordCastNode(Stamp stamp, ValueNode input) {
         super(stamp);
         this.input = input;