# HG changeset patch # User Miguel Garcia # Date 1399207449 -7200 # Node ID 7f492a524ca7463a1fcc5c1abdb355e59621e258 # Parent 5d0dd6a6f6b3f95fd95a7c92332ecd6091e28584 [flow-sensitive] bug fix, simplify ShortCircuitOrNode when of check-cast form diff -r 5d0dd6a6f6b3 -r 7f492a524ca7 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/EquationalReasoner.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/EquationalReasoner.java Sun May 04 01:28:07 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/EquationalReasoner.java Sun May 04 14:44:09 2014 +0200 @@ -441,6 +441,8 @@ return baseCaseIsNullNode((IsNullNode) condition); } else if (condition instanceof ObjectEqualsNode) { return baseCaseObjectEqualsNode((ObjectEqualsNode) condition); + } else if (condition instanceof ShortCircuitOrNode) { + return baseCaseShortCircuitOrNode((ShortCircuitOrNode) condition); } } return condition; @@ -515,6 +517,38 @@ } /** + * The following is tried: + * + *
    + *
  1. + * A {@link com.oracle.graal.phases.common.cfs.Witness} that is at check-cast level level + * doesn't entail {@link com.oracle.graal.nodes.calc.IsNullNode} (on its own) nor + * {@link com.oracle.graal.nodes.java.InstanceOfNode} (also on its own) but of course it entails + * (IsNull || IsInstanceOf). Good thing + * {@link com.oracle.graal.phases.common.cfs.CastCheckExtractor} detects that very pattern.
  2. + *
  3. + * Otherwise return the unmodified argument (later on, + * {@link #deverbosifyFloatingNode(com.oracle.graal.nodes.calc.FloatingNode)} will attempt to + * simplify the {@link com.oracle.graal.nodes.ShortCircuitOrNode}).
  4. + *
+ * + * @return a {@link com.oracle.graal.nodes.LogicConstantNode}, in case a reduction was made; + * otherwise the unmodified argument. + */ + private LogicNode baseCaseShortCircuitOrNode(ShortCircuitOrNode orNode) { + CastCheckExtractor cast = CastCheckExtractor.extract(orNode); + if (cast != null) { + if (state.knownToConform(cast.subject, cast.type)) { + return trueConstant; + } else if (state.knownNotToConform(cast.subject, cast.type)) { + return falseConstant; + } + return orNode; + } + return orNode; + } + + /** * It's always ok to use "downcast(object)" instead of " object" * because this method re-wraps the argument in a {@link com.oracle.graal.nodes.PiNode} only if * the new stamp is strictly more refined than the original. diff -r 5d0dd6a6f6b3 -r 7f492a524ca7 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/State.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/State.java Sun May 04 01:28:07 2014 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/cfs/State.java Sun May 04 14:44:09 2014 +0200 @@ -422,7 +422,8 @@ assert FlowUtil.hasLegalObjectStamp(object); assert !to.isPrimitive(); final ValueNode scrutinee = GraphUtil.unproxify(object); - if (isNull(scrutinee)) { + if (!isNonNull(scrutinee)) { + // unless `null` can be ruled out, a positive answer isn't safe return false; } ResolvedJavaType stampType = StampTool.typeOrNull(object);