# HG changeset patch # User Thomas Wuerthinger # Date 1451688903 -3600 # Node ID f1e6458a3f33aba2a1b36b2458ea5e8253c09754 # Parent c3fa52fbb9ce6d2fc85b772e95d8833515143af7 Perform DCE for old loop phis after peeling. diff -r c3fa52fbb9ce -r f1e6458a3f33 graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopFragmentInside.java --- a/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopFragmentInside.java Fri Jan 01 20:47:47 2016 +0100 +++ b/graal/com.oracle.graal.loop/src/com/oracle/graal/loop/LoopFragmentInside.java Fri Jan 01 23:55:03 2016 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -234,7 +234,8 @@ } markStateNodes(loopBegin, usagesToPatch); - for (PhiNode phi : loopBegin.phis().snapshot()) { + List oldPhis = loopBegin.phis().snapshot(); + for (PhiNode phi : oldPhis) { if (phi.hasNoUsages()) { continue; } @@ -275,7 +276,32 @@ } } - for (PhiNode deadPhi : loopBegin.phis().filter(n -> n.hasNoUsages()).snapshot()) { + int oldPhisSize; + do { + oldPhisSize = oldPhis.size(); + int i = 0; + outer: while (i < oldPhisSize) { + PhiNode oldPhi = oldPhis.get(i); + for (Node usage : oldPhi.usages()) { + if (usage instanceof PhiNode && oldPhis.contains(usage)) { + // Do not mark. + } else { + // Mark alive by removing from delete set. + oldPhis.set(i, oldPhis.get(oldPhisSize - 1)); + oldPhisSize--; + continue outer; + } + } + i++; + } + // Check for progress. + } while (oldPhisSize != oldPhis.size()); + + for (PhiNode deadPhi : oldPhis) { + deadPhi.clearInputs(); + } + + for (PhiNode deadPhi : oldPhis) { if (deadPhi.isAlive()) { GraphUtil.killWithUnusedFloatingInputs(deadPhi); }