# HG changeset patch # User Thomas Wuerthinger # Date 1367072535 -7200 # Node ID 3b4f3f92879ecc0246554fcc7fa0726005549b5d # Parent 1ac1247bb98dead0a64e2f4386e6ebfeba96ade0 Implement swapping for distinct conditions on same values. diff -r 1ac1247bb98d -r 3b4f3f92879e graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java Sat Apr 27 15:38:55 2013 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java Sat Apr 27 16:22:15 2013 +0200 @@ -166,7 +166,7 @@ return; } - if (falseSuccessor().guards().isEmpty() && falseSuccessor().next() instanceof IfNode) { + if (falseSuccessor().usages().isEmpty() && falseSuccessor().next() instanceof IfNode) { BeginNode intermediateBegin = falseSuccessor(); IfNode nextIf = (IfNode) intermediateBegin.next(); double probabilityB = (1.0 - this.trueSuccessorProbability) * nextIf.trueSuccessorProbability; @@ -208,7 +208,7 @@ JavaTypeProfile profileA = instanceOfA.profile(); JavaTypeProfile profileB = instanceOfB.profile(); - Debug.log("Can swap instanceof for types (%s, %.3f) and (%s, %.3f)", instanceOfA.type(), probabilityA, instanceOfB.type(), probabilityB); + Debug.log("Can swap instanceof for types %s and %s", instanceOfA.type(), instanceOfB.type()); JavaTypeProfile newProfile = null; if (profileA != null && profileB != null) { double remainder = 1.0; @@ -246,6 +246,27 @@ return true; } } + } else if (a instanceof CompareNode) { + CompareNode compareA = (CompareNode) a; + Condition conditionA = compareA.condition(); + if (b instanceof CompareNode) { + CompareNode compareB = (CompareNode) b; + Condition conditionB = null; + if (compareB.x() == compareA.x() && compareB.y() == compareA.y()) { + conditionB = compareB.condition(); + } else if (compareB.x() == compareA.y() && compareB.y() == compareA.x()) { + conditionB = compareB.condition().mirror(); + } + + if (conditionB != null) { + Condition combined = conditionA.join(conditionB); + if (combined == null) { + // The two conditions are disjoint => can reorder. + Debug.log("Can swap disjoint coditions on same values: %s and %s", conditionA, conditionB); + return true; + } + } + } } return false;