Mercurial > hg > truffle
changeset 21037:3fc34aafea30
Conditional elimination: check if conditional has known value already
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Wed, 15 Apr 2015 12:35:38 +0200 |
parents | 953666b61a23 |
children | 6868faf48f02 |
files | graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/DominatorConditionalEliminationPhase.java |
diffstat | 1 files changed, 24 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- 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<Runnable> undoOperations) { @@ -301,7 +306,14 @@ return proxiedGuard; } - private boolean tryProofCondition(Node node, BiConsumer<ValueNode, Boolean> rewireGuardFunction) { + private boolean tryProofCondition(LogicNode node, BiConsumer<ValueNode, Boolean> 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()) {