use of org.graalvm.compiler.nodes.calc.IntegerEqualsNode in project graal by oracle.
the class IfNode method canonicalizeConditionalCascade.
private ValueNode canonicalizeConditionalCascade(SimplifierTool tool, ValueNode trueValue, ValueNode falseValue) {
if (trueValue.getStackKind() != falseValue.getStackKind()) {
return null;
}
if (trueValue.getStackKind() != JavaKind.Int && trueValue.getStackKind() != JavaKind.Long) {
return null;
}
if (trueValue.isConstant() && falseValue.isConstant()) {
return graph().unique(new ConditionalNode(condition(), trueValue, falseValue));
} else if (!graph().isAfterExpandLogic()) {
ConditionalNode conditional = null;
ValueNode constant = null;
boolean negateCondition;
if (trueValue instanceof ConditionalNode && falseValue.isConstant()) {
conditional = (ConditionalNode) trueValue;
constant = falseValue;
negateCondition = true;
} else if (falseValue instanceof ConditionalNode && trueValue.isConstant()) {
conditional = (ConditionalNode) falseValue;
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;
}
if (otherValue != null && otherValue.isConstant()) {
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;
NodeView view = NodeView.from(tool);
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(), conditional.trueValue().stamp(view).getStackKind(), false));
}
}
}
}
return null;
}
use of org.graalvm.compiler.nodes.calc.IntegerEqualsNode in project graal by oracle.
the class IfNode method tryEliminateBoxedReferenceEquals.
/**
* Attempts to replace the following pattern:
*
* <pre>
* Integer x = ...;
* Integer y = ...;
* if ((x == y) || x.equals(y)) { ... }
* </pre>
*
* with:
*
* <pre>
* Integer x = ...;
* Integer y = ...;
* if (x.equals(y)) { ... }
* </pre>
*
* whenever the probability that the reference check will pass is relatively small.
*
* See GR-1315 for more information.
*/
private boolean tryEliminateBoxedReferenceEquals(SimplifierTool tool) {
if (!(condition instanceof ObjectEqualsNode)) {
return false;
}
MetaAccessProvider meta = tool.getMetaAccess();
ObjectEqualsNode equalsCondition = (ObjectEqualsNode) condition;
ValueNode x = equalsCondition.getX();
ValueNode y = equalsCondition.getY();
ResolvedJavaType integerType = meta.lookupJavaType(Integer.class);
// At least one argument for reference equal must be a boxed primitive.
NodeView view = NodeView.from(tool);
if (!x.stamp(view).javaType(meta).equals(integerType) && !y.stamp(view).javaType(meta).equals(integerType)) {
return false;
}
// no sense to eliminate it.
if (getTrueSuccessorProbability() > 0.4) {
return false;
}
// True branch must be empty.
if (trueSuccessor instanceof BeginNode || trueSuccessor instanceof LoopExitNode) {
if (trueSuccessor.next() instanceof EndNode) {
// Empty true branch.
} else {
return false;
}
} else {
return false;
}
// False branch must only check the unboxed values.
UnboxNode unbox = null;
FixedGuardNode unboxCheck = null;
for (FixedNode node : falseSuccessor.getBlockNodes()) {
if (!(node instanceof BeginNode || node instanceof UnboxNode || node instanceof FixedGuardNode || node instanceof EndNode || node instanceof LoadFieldNode || node instanceof LoopExitNode)) {
return false;
}
if (node instanceof UnboxNode) {
if (unbox == null) {
unbox = (UnboxNode) node;
} else {
return false;
}
}
if (!(node instanceof FixedGuardNode)) {
continue;
}
FixedGuardNode fixed = (FixedGuardNode) node;
if (!(fixed.condition() instanceof IntegerEqualsNode)) {
continue;
}
IntegerEqualsNode equals = (IntegerEqualsNode) fixed.condition();
if ((isUnboxedFrom(meta, view, equals.getX(), x) && isUnboxedFrom(meta, view, equals.getY(), y)) || (isUnboxedFrom(meta, view, equals.getX(), y) && isUnboxedFrom(meta, view, equals.getY(), x))) {
unboxCheck = fixed;
}
}
if (unbox == null || unboxCheck == null) {
return false;
}
// Falsify the reference check.
setCondition(graph().addOrUniqueWithInputs(LogicConstantNode.contradiction()));
return true;
}
Aggregations