# HG changeset patch # User Thomas Wuerthinger # Date 1423774915 -3600 # Node ID 0e4449e992c6a7fa572236d95fd2429c040a4a2b # Parent ae87324c37d60db88f0a7cddb29decabd931c1b4 Make Class#isInstance plugin also work if only the Class is constant. diff -r ae87324c37d6 -r 0e4449e992c6 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Thu Feb 12 21:37:38 2015 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotGraphBuilderPlugins.java Thu Feb 12 22:01:55 2015 +0100 @@ -32,7 +32,9 @@ import com.oracle.graal.java.GraphBuilderPlugins.Registration; import com.oracle.graal.java.GraphBuilderPlugins.Registration.Receiver; import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.options.*; @@ -75,10 +77,11 @@ }); r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() { public boolean apply(GraphBuilderContext builder, ValueNode rcvr, ValueNode object) { - if (rcvr.isConstant() && !rcvr.isNullConstant() && object.isConstant()) { + if (rcvr.isConstant() && !rcvr.isNullConstant()) { ResolvedJavaType type = builder.getConstantReflection().asJavaType(rcvr.asConstant()); if (type != null && !type.isPrimitive()) { - builder.push(Kind.Boolean.getStackKind(), builder.append(ConstantNode.forBoolean(type.isInstance(object.asJavaConstant())))); + LogicNode node = builder.append(InstanceOfNode.create(type, object, null)); + builder.push(Kind.Boolean.getStackKind(), builder.append(ConditionalNode.create(node))); return true; } } diff -r ae87324c37d6 -r 0e4449e992c6 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java Thu Feb 12 21:37:38 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java Thu Feb 12 22:01:55 2015 +0100 @@ -60,6 +60,18 @@ this.falseValue = falseValue; } + public static ValueNode create(LogicNode condition) { + return create(condition, ConstantNode.forInt(1, condition.graph()), ConstantNode.forInt(0, condition.graph())); + } + + public static ValueNode create(LogicNode condition, ValueNode trueValue, ValueNode falseValue) { + ValueNode synonym = findSynonym(condition, trueValue, falseValue); + if (synonym != null) { + return synonym; + } + return new ConditionalNode(condition, trueValue, falseValue); + } + @Override public boolean inferStamp() { return updateStamp(trueValue.stamp().meet(falseValue.stamp())); @@ -75,9 +87,9 @@ @Override public ValueNode canonical(CanonicalizerTool tool) { - if (condition instanceof LogicNegationNode) { - LogicNegationNode negated = (LogicNegationNode) condition; - return new ConditionalNode(negated.getValue(), falseValue(), trueValue()); + ValueNode synonym = findSynonym(condition, trueValue(), falseValue()); + if (synonym != null) { + return synonym; } // this optimizes the case where a value that can only be 0 or 1 is materialized to 0 or 1 @@ -92,14 +104,6 @@ } } } - if (condition instanceof LogicConstantNode) { - LogicConstantNode c = (LogicConstantNode) condition; - if (c.getValue()) { - return trueValue(); - } else { - return falseValue(); - } - } if (condition instanceof CompareNode && ((CompareNode) condition).condition() == Condition.EQ) { // optimize the pattern (x == y) ? x : y CompareNode compare = (CompareNode) condition; @@ -114,6 +118,22 @@ return this; } + private static ValueNode findSynonym(ValueNode condition, ValueNode falseValue, ValueNode trueValue) { + if (condition instanceof LogicNegationNode) { + LogicNegationNode negated = (LogicNegationNode) condition; + return ConditionalNode.create(negated.getValue(), falseValue, trueValue); + } + if (condition instanceof LogicConstantNode) { + LogicConstantNode c = (LogicConstantNode) condition; + if (c.getValue()) { + return trueValue; + } else { + return falseValue; + } + } + return null; + } + @Override public void generate(NodeLIRBuilderTool generator) { generator.emitConditional(this);