src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
*** old/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java Mon Mar 20 17:40:25 2017
--- new/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java Mon Mar 20 17:40:25 2017
*** 27,39 ****
--- 27,37 ----
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.graalvm.compiler.core.common.CollectionsFactory;
import org.graalvm.compiler.core.common.calc.Condition;
import org.graalvm.compiler.core.common.type.IntegerStamp;
import org.graalvm.compiler.core.common.type.Stamp;
import org.graalvm.compiler.core.common.type.StampFactory;
import org.graalvm.compiler.debug.Debug;
*** 48,63 ****
--- 46,65 ----
import org.graalvm.compiler.nodeinfo.InputType;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.calc.CompareNode;
import org.graalvm.compiler.nodes.calc.ConditionalNode;
import org.graalvm.compiler.nodes.calc.IntegerBelowNode;
+ import org.graalvm.compiler.nodes.calc.IntegerEqualsNode;
import org.graalvm.compiler.nodes.calc.IntegerLessThanNode;
import org.graalvm.compiler.nodes.calc.IsNullNode;
+ import org.graalvm.compiler.nodes.calc.NormalizeCompareNode;
import org.graalvm.compiler.nodes.java.InstanceOfNode;
import org.graalvm.compiler.nodes.spi.LIRLowerable;
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
import org.graalvm.compiler.nodes.util.GraphUtil;
+ import org.graalvm.util.EconomicMap;
+ import org.graalvm.util.Equivalence;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.ConstantReflectionProvider;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
*** 271,280 ****
--- 273,287 ----
}
MergeNode merge = (MergeNode) trueEnd.merge();
if (merge.usages().count() != 1 || merge.phis().count() != 1) {
return false;
}
+
+ if (trueSuccessor().anchored().isNotEmpty() || falseSuccessor().anchored().isNotEmpty()) {
+ return false;
+ }
+
PhiNode phi = merge.phis().first();
ValueNode falseValue = phi.valueAt(falseEnd);
ValueNode trueValue = phi.valueAt(trueEnd);
ValueNode result = ConditionalNode.canonicalizeConditional(condition, trueValue, falseValue, phi.stamp());
*** 556,566 ****
--- 563,573 ----
removeThroughFalseBranch(tool);
return true;
} else if (distinct == 1) {
ValueNode trueValue = singlePhi.valueAt(trueEnd);
ValueNode falseValue = singlePhi.valueAt(falseEnd);
! ConditionalNode conditional = canonicalizeConditionalCascade(trueValue, falseValue);
! ValueNode conditional = canonicalizeConditionalCascade(trueValue, falseValue);
if (conditional != null) {
singlePhi.setValueAt(trueEnd, conditional);
removeThroughFalseBranch(tool);
return true;
}
*** 593,608 ****
--- 600,615 ----
protected void removeThroughFalseBranch(SimplifierTool tool) {
AbstractBeginNode trueBegin = trueSuccessor();
graph().removeSplitPropagate(this, trueBegin, tool);
tool.addToWorkList(trueBegin);
- if (condition() != null && condition().isAlive() && condition().hasNoUsages()) {
! GraphUtil.killWithUnusedFloatingInputs(condition());
! GraphUtil.tryKillUnused(condition());
}
}
! private ConditionalNode canonicalizeConditionalCascade(ValueNode trueValue, ValueNode falseValue) {
! private ValueNode canonicalizeConditionalCascade(ValueNode trueValue, ValueNode falseValue) {
if (trueValue.getStackKind() != falseValue.getStackKind()) {
return null;
}
if (trueValue.getStackKind() != JavaKind.Int && trueValue.getStackKind() != JavaKind.Long) {
return null;
*** 622,647 ****
--- 629,672 ----
constant = trueValue;
negateCondition = false;
} else {
return null;
}
! boolean negateConditionalCondition = false;
! ValueNode otherValue = null;
if (constant == conditional.trueValue()) {
otherValue = conditional.falseValue();
negateConditionalCondition = false;
} else if (constant == conditional.falseValue()) {
otherValue = conditional.trueValue();
negateConditionalCondition = true;
} else {
return null;
}
! if (otherValue.isConstant()) {
! if (otherValue != null) {
+ if (otherValue.isConstant() && graph().allowShortCircuitOr()) {
double shortCutProbability = probability(trueSuccessor());
LogicNode newCondition = LogicNode.or(condition(), negateCondition, conditional.condition(), negateConditionalCondition, shortCutProbability);
return graph().unique(new ConditionalNode(newCondition, constant, otherValue));
}
+ } else if (!negateCondition && constant.isJavaConstant() && conditional.trueValue().isJavaConstant() && conditional.falseValue().isJavaConstant()) {
+ IntegerLessThanNode lessThan = null;
+ IntegerEqualsNode equals = null;
+ if (condition() instanceof IntegerLessThanNode && conditional.condition() instanceof IntegerEqualsNode && constant.asJavaConstant().asLong() == -1 &&
+ conditional.trueValue().asJavaConstant().asLong() == 0 && conditional.falseValue().asJavaConstant().asLong() == 1) {
+ lessThan = (IntegerLessThanNode) condition();
+ equals = (IntegerEqualsNode) conditional.condition();
+ } else if (condition() instanceof IntegerEqualsNode && conditional.condition() instanceof IntegerLessThanNode && constant.asJavaConstant().asLong() == 0 &&
+ conditional.trueValue().asJavaConstant().asLong() == -1 && conditional.falseValue().asJavaConstant().asLong() == 1) {
+ lessThan = (IntegerLessThanNode) conditional.condition();
+ equals = (IntegerEqualsNode) condition();
+ }
+ if (lessThan != null) {
+ assert equals != null;
+ if ((lessThan.getX() == equals.getX() && lessThan.getY() == equals.getY()) || (lessThan.getX() == equals.getY() && lessThan.getY() == equals.getX())) {
+ return graph().unique(new NormalizeCompareNode(lessThan.getX(), lessThan.getY(), false));
+ }
+ }
+ }
}
return null;
}
/**
*** 650,659 ****
--- 675,689 ----
* of the IfNode. Any undecidable tests will continue to use the original IfNode.
*
* @param tool
*/
private boolean splitIfAtPhi(SimplifierTool tool) {
+ if (graph().getGuardsStage().areFrameStatesAtSideEffects()) {
+ // Disabled until we make sure we have no FrameState-less merges at this stage
+ return false;
+ }
+
if (!(predecessor() instanceof MergeNode)) {
return false;
}
MergeNode merge = (MergeNode) predecessor();
if (merge.forwardEndCount() == 1) {
*** 736,745 ****
--- 766,776 ----
falseMerge.addForwardEnd((EndNode) falseBegin.next());
end.safeDelete();
}
}
+
transferProxies(trueSuccessor(), trueMerge);
transferProxies(falseSuccessor(), falseMerge);
cleanupMerge(tool, merge);
cleanupMerge(tool, trueMerge);
*** 790,800 ****
--- 821,831 ----
* @return an improved LogicNode or the original condition
*/
@SuppressWarnings("unchecked")
private static LogicNode computeCondition(SimplifierTool tool, LogicNode condition, PhiNode phi, Node value) {
if (condition instanceof ShortCircuitOrNode) {
! if (condition.graph().getGuardsStage().areDeoptsFixed() && condition.graph().allowShortCircuitOr()) {
ShortCircuitOrNode orNode = (ShortCircuitOrNode) condition;
LogicNode resultX = computeCondition(tool, orNode.x, phi, value);
LogicNode resultY = computeCondition(tool, orNode.y, phi, value);
if (resultX != orNode.x || resultY != orNode.y) {
LogicNode result = orNode.canonical(tool, resultX, resultY);
*** 970,980 ****
--- 1001,1011 ----
return false;
}
List<EndNode> falseEnds = new ArrayList<>(mergePredecessors.size());
List<EndNode> trueEnds = new ArrayList<>(mergePredecessors.size());
! Map<AbstractEndNode, ValueNode> phiValues = CollectionsFactory.newMap(mergePredecessors.size());
! EconomicMap<AbstractEndNode, ValueNode> phiValues = EconomicMap.create(Equivalence.IDENTITY, mergePredecessors.size());
AbstractBeginNode oldFalseSuccessor = falseSuccessor();
AbstractBeginNode oldTrueSuccessor = trueSuccessor();
setFalseSuccessor(null);
*** 1109,1119 ****
--- 1140,1150 ----
* {@linkplain SimplifierTool#addToWorkList(org.graalvm.compiler.graph.Node) work list}.
*
* @param oldMerge the merge being removed
* @param phiValues the values of the phi at the merge, keyed by the merge ends
*/
! private void connectEnds(List<EndNode> ends, EconomicMap<AbstractEndNode, ValueNode> phiValues, AbstractBeginNode successor, AbstractMergeNode oldMerge, SimplifierTool tool) {
if (!ends.isEmpty()) {
if (ends.size() == 1) {
AbstractEndNode end = ends.get(0);
((FixedWithNextNode) end.predecessor()).setNext(successor);
oldMerge.removeEnd(end);
*** 1182,1187 ****
--- 1213,1235 ----
}
public AbstractBeginNode getSuccessor(boolean result) {
return result ? this.trueSuccessor() : this.falseSuccessor();
}
+
+ @Override
+ public boolean setProbability(AbstractBeginNode successor, double value) {
+ if (successor == this.trueSuccessor()) {
+ this.setTrueSuccessorProbability(value);
+ return true;
+ } else if (successor == this.falseSuccessor()) {
+ this.setTrueSuccessorProbability(1.0 - value);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public int getSuccessorCount() {
+ return 2;
+ }
}
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/IfNode.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File