# HG changeset patch # User Gilles Duboscq # Date 1429379782 -7200 # Node ID 6868faf48f023ed540909b7e97fc0409dc669ffc # Parent 3fc34aafea304a46210af19563ed1a37ae102189 Conditional Elimination: tryProofCondition: return true if ShortCircuitOrNode could be proven diff -r 3fc34aafea30 -r 6868faf48f02 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java Wed Apr 15 12:35:38 2015 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java Sat Apr 18 19:56:22 2015 +0200 @@ -222,6 +222,7 @@ node.replaceAtPredecessor(deopt); GraphUtil.killCFG(node); } + return true; }); } } @@ -237,6 +238,7 @@ if (survivingSuccessor instanceof BeginNode) { undoOperations.add(() -> ((BeginNode) survivingSuccessor).trySimplify()); } + return true; }); } @@ -276,12 +278,11 @@ } } - private boolean rewireGuards(ValueNode guard, boolean result, BiConsumer rewireGuardFunction) { + private boolean rewireGuards(ValueNode guard, boolean result, GuardRewirer rewireGuardFunction) { assert guard instanceof GuardingNode; metricStampsFound.increment(); ValueNode proxiedGuard = proxyGuard(guard); - rewireGuardFunction.accept(proxiedGuard, result); - return true; + return rewireGuardFunction.rewire(proxiedGuard, result); } private ValueNode proxyGuard(ValueNode guard) { @@ -306,7 +307,18 @@ return proxiedGuard; } - private boolean tryProofCondition(LogicNode node, BiConsumer rewireGuardFunction) { + @FunctionalInterface + private interface GuardRewirer { + /** + * Called if the condition could be proven to have a constant value ({@code result}) + * under {@code guard}. + * + * Return whether a transformation could be applied. + */ + boolean rewire(ValueNode guard, boolean result); + } + + private boolean tryProofCondition(LogicNode node, GuardRewirer rewireGuardFunction) { for (InfoElement infoElement : getInfoElements(node)) { Stamp stamp = infoElement.getStamp(); JavaConstant constant = (JavaConstant) stamp.asConstant(); @@ -352,14 +364,15 @@ } else if (node instanceof ShortCircuitOrNode) { final ShortCircuitOrNode shortCircuitOrNode = (ShortCircuitOrNode) node; if (this.loopExits.isEmpty()) { - tryProofCondition(shortCircuitOrNode.getX(), (guard, result) -> { + return tryProofCondition(shortCircuitOrNode.getX(), (guard, result) -> { if (result == !shortCircuitOrNode.isXNegated()) { - rewireGuards(guard, result, rewireGuardFunction); + return rewireGuards(guard, result, rewireGuardFunction); } else { - tryProofCondition(shortCircuitOrNode.getY(), (innerGuard, innerResult) -> { + return tryProofCondition(shortCircuitOrNode.getY(), (innerGuard, innerResult) -> { if (innerGuard == guard) { - rewireGuards(guard, shortCircuitOrNode.isYNegated() ? !innerResult : innerResult, rewireGuardFunction); + return rewireGuards(guard, shortCircuitOrNode.isYNegated() ? !innerResult : innerResult, rewireGuardFunction); } + return false; }); } }); @@ -395,6 +408,7 @@ node.replaceAtUsages(valueAnchor); node.graph().replaceFixedWithFixed(node, valueAnchor); } + return true; }); } @@ -409,6 +423,7 @@ beginNode.setNext(deopt); GraphUtil.killCFG(next); } + return true; })) { registerNewCondition(node.condition(), node.isNegated(), node, undoOperations); } @@ -426,6 +441,7 @@ node.replaceAtPredecessor(deopt); GraphUtil.killCFG(node); } + return true; })) { registerNewCondition(node.condition(), node.isNegated(), node, undoOperations); }