# HG changeset patch # User Tom Rodriguez # Date 1405528879 25200 # Node ID 5bf37ff211bd2d0af40aeee0f81b1ce48000edfb # Parent 5936fa0edb6fc7c75ee75b4d420aa22085cf502d consider equivalent phi inputs when simplfiying empty ifs diff -r 5936fa0edb6f -r 5bf37ff211bd 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 Wed Jul 16 15:29:24 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java Wed Jul 16 09:41:19 2014 -0700 @@ -485,24 +485,32 @@ AbstractEndNode falseEnd = (AbstractEndNode) falseSuccessor().next(); MergeNode merge = trueEnd.merge(); if (merge == falseEnd.merge() && trueSuccessor().anchored().isEmpty() && falseSuccessor().anchored().isEmpty()) { - Iterator phis = merge.phis().iterator(); - if (!phis.hasNext()) { + PhiNode singlePhi = null; + int distinct = 0; + for (PhiNode phi : merge.phis()) { + ValueNode trueValue = phi.valueAt(trueEnd); + ValueNode falseValue = phi.valueAt(falseEnd); + if (trueValue != falseValue) { + distinct++; + singlePhi = phi; + } + } + if (distinct == 0) { + /* + * Multiple phis but merging same values for true and false, so simply delete + * the path + */ tool.addToWorkList(condition()); removeThroughFalseBranch(tool); return true; - } else { - PhiNode singlePhi = phis.next(); - if (!phis.hasNext()) { - // one phi at the merge of an otherwise empty if construct: try to convert - // into a MaterializeNode - ValueNode trueValue = singlePhi.valueAt(trueEnd); - ValueNode falseValue = singlePhi.valueAt(falseEnd); - ConditionalNode conditional = canonicalizeConditionalCascade(trueValue, falseValue); - if (conditional != null) { - singlePhi.setValueAt(trueEnd, conditional); - removeThroughFalseBranch(tool); - return true; - } + } else if (distinct == 1) { + ValueNode trueValue = singlePhi.valueAt(trueEnd); + ValueNode falseValue = singlePhi.valueAt(falseEnd); + ConditionalNode conditional = canonicalizeConditionalCascade(trueValue, falseValue); + if (conditional != null) { + singlePhi.setValueAt(trueEnd, conditional); + removeThroughFalseBranch(tool); + return true; } } } @@ -512,14 +520,18 @@ ReturnNode falseEnd = (ReturnNode) falseSuccessor().next(); ValueNode trueValue = trueEnd.result(); ValueNode falseValue = falseEnd.result(); - ConditionalNode conditional = null; + ValueNode value = null; if (trueValue != null) { - conditional = canonicalizeConditionalCascade(trueValue, falseValue); - if (conditional == null) { - return false; + if (trueValue == falseValue) { + value = trueValue; + } else { + value = canonicalizeConditionalCascade(trueValue, falseValue); + if (value == null) { + return false; + } } } - ReturnNode newReturn = graph().add(new ReturnNode(conditional)); + ReturnNode newReturn = graph().add(new ReturnNode(value)); replaceAtPredecessor(newReturn); GraphUtil.killCFG(this); return true;