# HG changeset patch # User Thomas Wuerthinger # Date 1448218418 -3600 # Node ID 4e72c50bb9c1e11bf775ab66c2b182b5c7270d31 # Parent 6c5f70cd3ed8e167738ab8db75c435d94d9dc756 Improve handling of pi nodes that directly follow access nodes. diff -r 6c5f70cd3ed8 -r 4e72c50bb9c1 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java Sun Nov 22 19:52:42 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/PiNode.java Sun Nov 22 19:53:38 2015 +0100 @@ -36,6 +36,9 @@ import com.oracle.graal.graph.spi.CanonicalizerTool; import com.oracle.graal.nodeinfo.NodeInfo; import com.oracle.graal.nodes.extended.GuardingNode; +import com.oracle.graal.nodes.extended.UnsafeLoadNode; +import com.oracle.graal.nodes.java.LoadFieldNode; +import com.oracle.graal.nodes.java.LoadIndexedNode; import com.oracle.graal.nodes.spi.LIRLowerable; import com.oracle.graal.nodes.spi.NodeLIRBuilderTool; import com.oracle.graal.nodes.spi.ValueProxy; @@ -116,19 +119,42 @@ return this; } inferStamp(); - if (stamp().equals(object().stamp())) { - return object(); + ValueNode o = object(); + + // The pi node does not give any additional information => skip it. + if (stamp().equals(o.stamp())) { + return o; } - if (getGuard() != null) { - for (PiNode otherPi : getGuard().asNode().usages().filter(PiNode.class)) { - if (object() == otherPi.object() && stamp().equals(otherPi.stamp())) { - /* - * Two PiNodes with the same guard and same result, so return the one with the - * more precise piStamp. - */ - Stamp newStamp = piStamp.join(otherPi.piStamp); - if (newStamp.equals(otherPi.piStamp)) { - return otherPi; + + GuardingNode g = getGuard(); + if (g == null) { + // Try to merge the pi node with a load node. + if (o instanceof LoadFieldNode) { + LoadFieldNode loadFieldNode = (LoadFieldNode) o; + loadFieldNode.setStamp(loadFieldNode.stamp().improveWith(this.stamp())); + return loadFieldNode; + } else if (o instanceof UnsafeLoadNode) { + UnsafeLoadNode unsafeLoadNode = (UnsafeLoadNode) o; + unsafeLoadNode.setStamp(unsafeLoadNode.stamp().improveWith(this.stamp())); + return unsafeLoadNode; + } else if (o instanceof LoadIndexedNode) { + LoadIndexedNode loadIndexedNode = (LoadIndexedNode) o; + loadIndexedNode.setStamp(loadIndexedNode.stamp().improveWith(this.stamp())); + return loadIndexedNode; + } + } else { + for (Node n : g.asNode().usages()) { + if (n instanceof PiNode) { + PiNode otherPi = (PiNode) n; + if (o == otherPi.object() && stamp().equals(otherPi.stamp())) { + /* + * Two PiNodes with the same guard and same result, so return the one with + * the more precise piStamp. + */ + Stamp newStamp = piStamp.join(otherPi.piStamp); + if (newStamp.equals(otherPi.piStamp)) { + return otherPi; + } } } } diff -r 6c5f70cd3ed8 -r 4e72c50bb9c1 graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java --- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java Sun Nov 22 19:52:42 2015 +0100 +++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java Sun Nov 22 19:53:38 2015 +0100 @@ -228,7 +228,7 @@ * and constant folding could still eliminate the call to bailout(). However, we * also want to stop parsing, since we are sure that we will never need the * graph beyond the bailout point. - * + * * Therefore, we manually emit the call to bailout, which will be intrinsified * later when intrinsifications can no longer be delayed. The call is followed * by a NeverPartOfCompilationNode, which is a control sink and therefore stops @@ -398,17 +398,24 @@ } else { piStamp = StampFactory.declaredTrusted(javaType, nonNull.asJavaConstant().asInt() != 0); } - LogicNode compareNode = CompareNode.createCompareNode(object.graph(), Condition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection); - boolean skipAnchor = false; - if (compareNode instanceof LogicConstantNode) { - LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode; - if (logicConstantNode.getValue()) { - skipAnchor = true; + + ConditionAnchorNode valueAnchorNode = null; + if (condition.isConstant() && condition.asJavaConstant().asInt() == 1) { + // Nothing to do. + } else { + boolean skipAnchor = false; + LogicNode compareNode = CompareNode.createCompareNode(object.graph(), Condition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection); + + if (compareNode instanceof LogicConstantNode) { + LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode; + if (logicConstantNode.getValue()) { + skipAnchor = true; + } } - } - ConditionAnchorNode valueAnchorNode = null; - if (!skipAnchor) { - valueAnchorNode = b.add(new ConditionAnchorNode(compareNode)); + + if (!skipAnchor) { + valueAnchorNode = b.add(new ConditionAnchorNode(compareNode)); + } } b.addPush(JavaKind.Object, new PiNode(object, piStamp, valueAnchorNode)); }