# HG changeset patch # User Thomas Wuerthinger # Date 1376483260 -7200 # Node ID edf7e09ad382016ef879c59b1f126e57ed2cae40 # Parent 74ccfb4d39ec1f6f3ef7ce6ee9ead3a261a3d902 Search for correct replacement anchor for eliminated checkcasts in ConditionalEliminationPhase. diff -r 74ccfb4d39ec -r edf7e09ad382 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ConditionalEliminationPhase.java --- 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) {