# HG changeset patch # User Lukas Stadler # Date 1404219473 -7200 # Node ID 2cc0fea0cff61b03ccbccccd787a17acd3fbc72f # Parent 67f3267a8846fa598196f690d41edb3bd380246b fix ReadNode canonicalization for guard-type usages of null-checking reads diff -r 67f3267a8846 -r 2cc0fea0cff6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java --- 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) && diff -r 67f3267a8846 -r 2cc0fea0cff6 graal/com.oracle.graal.word/src/com/oracle/graal/word/nodes/WordCastNode.java --- 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;