# HG changeset patch # User Gilles Duboscq # Date 1349099583 -7200 # Node ID 6f2b35ef59b075200cc927a0fffe6d85701d014c # Parent 41f0849e107b7306080071a3319709e2b39e443c Fix problem in MemoryPhi creation during FloatingRead, add an assert to detect this kind of problems diff -r 41f0849e107b -r 6f2b35ef59b0 graal/com.oracle.graal.compiler.phases/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java --- a/graal/com.oracle.graal.compiler.phases/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java Sun Sep 30 21:44:03 2012 +0200 +++ b/graal/com.oracle.graal.compiler.phases/src/com/oracle/graal/compiler/phases/FloatingReadPhase.java Mon Oct 01 15:53:03 2012 +0200 @@ -102,17 +102,17 @@ keys.add(key); } } + @SuppressWarnings("unchecked") + IdentityHashMap newMemorySnapshot = (IdentityHashMap) lastMemorySnapshot.clone(); for (Object key : keys) { ValueNode merged = lastMemorySnapshot.get(key); if (merged == null) { merged = lastMemorySnapshot.get(LocationNode.ANY_LOCATION); } - Iterator it = withStates.iterator(); - int i = 1; + int mergedStatesCount = 1; boolean isPhi = false; - while (it.hasNext()) { - MemoryMap other = it.next(); + for (MemoryMap other : withStates) { ValueNode otherValue = other.lastMemorySnapshot.get(key); if (otherValue == null) { otherValue = other.lastMemorySnapshot.get(LocationNode.ANY_LOCATION); @@ -121,17 +121,19 @@ ((PhiNode) merged).addInput(otherValue); } else if (merged != otherValue) { PhiNode phi = merge.graph().add(new PhiNode(PhiType.Memory, merge)); - for (int j = 0; j < i; j++) { + for (int j = 0; j < mergedStatesCount; j++) { phi.addInput(merged); } phi.addInput(otherValue); merged = phi; isPhi = true; - lastMemorySnapshot.put(key, phi); + newMemorySnapshot.put(key, phi); } - i++; + mergedStatesCount++; } } + + lastMemorySnapshot = newMemorySnapshot; return true; } diff -r 41f0849e107b -r 6f2b35ef59b0 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java Sun Sep 30 21:44:03 2012 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PhiNode.java Mon Oct 01 15:53:03 2012 +0200 @@ -179,6 +179,7 @@ } public void addInput(ValueNode x) { + assert !(x instanceof PhiNode) || ((PhiNode) x).merge() instanceof LoopBeginNode || ((PhiNode) x).merge() != this.merge(); values.add(x); }