# HG changeset patch # User Gilles Duboscq # Date 1397480848 -7200 # Node ID 6f132c0219e94a32932e7d87d3d55b6eac0e5543 # Parent 393935e524e95591f0a107a91569b8d6d27df742 Remove dead phi loops during loop peeling diff -r 393935e524e9 -r 6f132c0219e9 graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopTransformations.java --- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopTransformations.java Mon Apr 14 11:46:36 2014 +0200 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopTransformations.java Mon Apr 14 15:07:28 2014 +0200 @@ -63,6 +63,7 @@ Mark mark = graph.getMark(); peel(loop); canonicalizer.applyIncremental(graph, context, mark); + loopBegin.removeDeadPhis(); loop.invalidateFragments(); if (iterations++ > UNROLL_LIMIT || graph.getNodeCount() > MaximumDesiredSize.getValue() * 3) { throw new BailoutException("FullUnroll : Graph seems to grow out of proportion"); diff -r 393935e524e9 -r 6f132c0219e9 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LoopBeginNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LoopBeginNode.java Mon Apr 14 11:46:36 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LoopBeginNode.java Mon Apr 14 15:07:28 2014 +0200 @@ -201,4 +201,27 @@ updateUsagesInterface(this.overflowGuard, overflowGuard); this.overflowGuard = overflowGuard; } + + /** + * Removes dead {@linkplain PhiNode phi nodes} hanging from this node. + * + * This method uses the heuristic that any node which not a phi node of this LoopBeginNode is + * alive. This allows the removal of dead phi loops. + */ + public void removeDeadPhis() { + Set alive = new HashSet<>(); + for (PhiNode phi : phis()) { + NodePredicate isAlive = u -> !isPhiAtMerge(u) || alive.contains(u); + if (phi.usages().filter(isAlive).isNotEmpty()) { + alive.add(phi); + for (PhiNode keptAlive : phi.values().filter(PhiNode.class).filter(isAlive.negate())) { + alive.add(keptAlive); + } + } + } + for (PhiNode phi : phis().filter(((NodePredicate) alive::contains).negate()).snapshot()) { + phi.replaceAtUsages(null); + phi.safeDelete(); + } + } }