Mercurial > hg > truffle
changeset 11305:edf7e09ad382
Search for correct replacement anchor for eliminated checkcasts in ConditionalEliminationPhase.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Wed, 14 Aug 2013 14:27:40 +0200 |
parents | 74ccfb4d39ec |
children | 2a26b86d7724 |
files | graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java |
diffstat | 1 files changed, 24 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Wed Aug 14 14:24:05 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java Wed Aug 14 14:27:40 2013 +0200 @@ -488,16 +488,36 @@ ResolvedJavaType type = state.getNodeType(object); if (isNull || (type != null && checkCast.type().isAssignableFrom(type))) { boolean nonNull = state.isNonNull(object); - ValueAnchorNode anchor = graph.add(new ValueAnchorNode()); + GuardingNode replacementAnchor = null; + if (nonNull) { + // Search for valid instanceof anchor. + for (InstanceOfNode instanceOfNode : object.usages().filter(InstanceOfNode.class)) { + if (instanceOfNode.type() == checkCast.type() && state.trueConditions.containsKey(instanceOfNode)) { + ValueNode v = state.trueConditions.get(instanceOfNode); + if (v instanceof GuardingNode) { + replacementAnchor = (GuardingNode) v; + } + } + } + } + ValueAnchorNode anchor = null; + if (replacementAnchor == null) { + anchor = graph.add(new ValueAnchorNode()); + replacementAnchor = anchor; + } PiNode piNode; if (isNull) { ConstantNode nullObject = ConstantNode.forObject(null, metaAccessProvider, graph); - piNode = graph.unique(new PiNode(nullObject, StampFactory.forConstant(nullObject.value, metaAccessProvider), anchor)); + piNode = graph.unique(new PiNode(nullObject, StampFactory.forConstant(nullObject.value, metaAccessProvider), replacementAnchor)); } else { - piNode = graph.unique(new PiNode(object, StampFactory.declared(type, nonNull), anchor)); + piNode = graph.unique(new PiNode(object, StampFactory.declared(type, nonNull), replacementAnchor)); } checkCast.replaceAtUsages(piNode); - graph.replaceFixedWithFixed(checkCast, anchor); + if (anchor != null) { + graph.replaceFixedWithFixed(checkCast, anchor); + } else { + graph.removeFixed(checkCast); + } metricCheckCastRemoved.increment(); } } else if (node instanceof IfNode) {