# HG changeset patch # User Gilles Duboscq # Date 1429094138 -7200 # Node ID 3fc34aafea304a46210af19563ed1a37ae102189 # Parent 953666b61a2321ee2378f7f62f2a16e404af3677 Conditional elimination: check if conditional has known value already diff -r 953666b61a23 -r 3fc34aafea30 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 Mon Mar 16 17:07:21 2015 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java Wed Apr 15 12:35:38 2015 +0200 @@ -208,18 +208,23 @@ } private void processCheckCast(CheckCastNode node) { - tryProofCondition(node, (guard, result) -> { - if (result) { - PiNode piNode = node.graph().unique(new PiNode(node.object(), node.stamp(), guard)); - node.replaceAtUsages(piNode); - GraphUtil.unlinkFixedNode(node); - node.safeDelete(); - } else { - DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode)); - node.replaceAtPredecessor(deopt); - GraphUtil.killCFG(node); + for (InfoElement infoElement : getInfoElements(node.object())) { + TriState result = node.tryFold(infoElement.getStamp()); + if (result.isKnown()) { + rewireGuards(infoElement.getGuard(), result.toBoolean(), (guard, checkCastResult) -> { + if (checkCastResult) { + PiNode piNode = node.graph().unique(new PiNode(node.object(), node.stamp(), guard)); + node.replaceAtUsages(piNode); + GraphUtil.unlinkFixedNode(node); + node.safeDelete(); + } else { + DeoptimizeNode deopt = node.graph().add(new DeoptimizeNode(InvalidateReprofile, UnreachedCode)); + node.replaceAtPredecessor(deopt); + GraphUtil.killCFG(node); + } + }); } - }); + } } private void processIf(IfNode node, List undoOperations) { @@ -301,7 +306,14 @@ return proxiedGuard; } - private boolean tryProofCondition(Node node, BiConsumer rewireGuardFunction) { + private boolean tryProofCondition(LogicNode node, BiConsumer rewireGuardFunction) { + for (InfoElement infoElement : getInfoElements(node)) { + Stamp stamp = infoElement.getStamp(); + JavaConstant constant = (JavaConstant) stamp.asConstant(); + if (constant != null) { + return rewireGuards(infoElement.getGuard(), constant.asBoolean(), rewireGuardFunction); + } + } if (node instanceof UnaryOpLogicNode) { UnaryOpLogicNode unaryLogicNode = (UnaryOpLogicNode) node; ValueNode value = unaryLogicNode.getValue(); @@ -337,14 +349,6 @@ return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction); } } - } else if (node instanceof CheckCastNode) { - CheckCastNode checkCastNode = (CheckCastNode) node; - for (InfoElement infoElement : getInfoElements(checkCastNode.object())) { - TriState result = checkCastNode.tryFold(infoElement.getStamp()); - if (result.isKnown()) { - return rewireGuards(infoElement.getGuard(), result.toBoolean(), rewireGuardFunction); - } - } } else if (node instanceof ShortCircuitOrNode) { final ShortCircuitOrNode shortCircuitOrNode = (ShortCircuitOrNode) node; if (this.loopExits.isEmpty()) {