# HG changeset patch # User Thomas Wuerthinger # Date 1423923595 -3600 # Node ID 03adf6499fee39992d12ed4cda4af5fd2490837e # Parent 96f2ae02fa4faeb8a92219480f41c7e1768abf9d Better graph building time canonicalizations for logical negation and conditional node. diff -r 96f2ae02fa4f -r 03adf6499fee graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Sat Feb 14 14:49:01 2015 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Sat Feb 14 15:19:55 2015 +0100 @@ -1689,7 +1689,16 @@ assert a.getKind() != Kind.Object && !cond.isUnsigned(); condition = genIntegerLessThan(a, b); } - condition = currentGraph.unique(condition); + + if (condition instanceof LogicNegationNode) { + LogicNegationNode logicNegationNode = (LogicNegationNode) condition; + negate = !negate; + condition = logicNegationNode.getValue(); + } + + if (condition.graph() == null) { + condition = currentGraph.unique(condition); + } if (condition instanceof LogicConstantNode) { LogicConstantNode constantLogicNode = (LogicConstantNode) condition; diff -r 96f2ae02fa4f -r 03adf6499fee graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LogicNegationNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LogicNegationNode.java Sat Feb 14 14:49:01 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/LogicNegationNode.java Sat Feb 14 15:19:55 2015 +0100 @@ -37,17 +37,35 @@ this.value = value; } + public static LogicNode create(LogicNode value) { + LogicNode synonym = findSynonym(value); + if (synonym != null) { + return synonym; + } + return new LogicNegationNode(value); + } + + private static LogicNode findSynonym(LogicNode value) { + if (value instanceof LogicConstantNode) { + LogicConstantNode logicConstantNode = (LogicConstantNode) value; + return LogicConstantNode.forBoolean(!logicConstantNode.getValue()); + } else if (value instanceof LogicNegationNode) { + return ((LogicNegationNode) value).getValue(); + } + return null; + } + public LogicNode getValue() { return value; } @Override public LogicNode canonical(CanonicalizerTool tool, LogicNode forValue) { - if (forValue instanceof LogicNegationNode) { - return ((LogicNegationNode) forValue).getValue(); - } else { - return this; + LogicNode synonym = findSynonym(forValue); + if (synonym != null) { + return synonym; } + return this; } } diff -r 96f2ae02fa4f -r 03adf6499fee graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ShortCircuitOrNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ShortCircuitOrNode.java Sat Feb 14 14:49:01 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ShortCircuitOrNode.java Sat Feb 14 15:19:55 2015 +0100 @@ -105,7 +105,7 @@ if (isXNegated()) { if (isYNegated()) { // !a || !a = !a - return new LogicNegationNode(forX); + return LogicNegationNode.create(forX); } else { // !a || a = true return LogicConstantNode.tautology(); diff -r 96f2ae02fa4f -r 03adf6499fee graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Sat Feb 14 14:49:01 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/CompareNode.java Sat Feb 14 15:19:55 2015 +0100 @@ -88,7 +88,7 @@ return conditionalNode.condition(); } else { assert falseResult == true; - return new LogicNegationNode(conditionalNode.condition()); + return LogicNegationNode.create(conditionalNode.condition()); } } diff -r 96f2ae02fa4f -r 03adf6499fee graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerBelowNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerBelowNode.java Sat Feb 14 14:49:01 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerBelowNode.java Sat Feb 14 15:19:55 2015 +0100 @@ -64,7 +64,7 @@ } if (forX.isConstant() && forX.asJavaConstant().asLong() == 0) { // 0 |<| y is the same as 0 != y - return new LogicNegationNode(CompareNode.createCompareNode(Condition.EQ, forX, forY, tool.getConstantReflection())); + return LogicNegationNode.create(CompareNode.createCompareNode(Condition.EQ, forX, forY, tool.getConstantReflection())); } return this; } diff -r 96f2ae02fa4f -r 03adf6499fee graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java Sat Feb 14 14:49:01 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/IntegerEqualsNode.java Sat Feb 14 15:19:55 2015 +0100 @@ -45,6 +45,24 @@ if (result != null) { return result; } else { + if (x instanceof ConditionalNode) { + ConditionalNode conditionalNode = (ConditionalNode) x; + if (conditionalNode.trueValue() == y) { + return conditionalNode.condition(); + } + if (conditionalNode.falseValue() == y) { + return LogicNegationNode.create(conditionalNode.condition()); + } + } else if (y instanceof ConditionalNode) { + ConditionalNode conditionalNode = (ConditionalNode) y; + if (conditionalNode.trueValue() == x) { + return conditionalNode.condition(); + } + if (conditionalNode.falseValue() == x) { + return LogicNegationNode.create(conditionalNode.condition()); + } + } + return new IntegerEqualsNode(x, y); } } diff -r 96f2ae02fa4f -r 03adf6499fee graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/InstanceOfNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/InstanceOfNode.java Sat Feb 14 14:49:01 2015 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/InstanceOfNode.java Sat Feb 14 15:19:55 2015 +0100 @@ -102,7 +102,7 @@ if (!nonNull) { // the instanceof matches if the object is non-null, so return true // depending on the null-ness. - return new LogicNegationNode(new IsNullNode(forValue)); + return LogicNegationNode.create(new IsNullNode(forValue)); } } return null;