use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class OrNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
ValueNode ret = super.canonical(tool, forX, forY);
if (ret != this) {
return ret;
}
return canonical(this, getOp(forX, forY), stamp(view), forX, forY, view);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class AddNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
ValueNode ret = super.canonical(tool, forX, forY);
if (ret != this) {
return ret;
}
if (forX.isConstant() && !forY.isConstant()) {
// we try to swap and canonicalize
ValueNode improvement = canonical(tool, forY, forX);
if (improvement != this) {
return improvement;
}
// if this fails we only swap
return new AddNode(forY, forX);
}
BinaryOp<Add> op = getOp(forX, forY);
NodeView view = NodeView.from(tool);
return canonical(this, op, forX, forY, view);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class AddNode method canonical.
private static ValueNode canonical(AddNode addNode, BinaryOp<Add> op, ValueNode forX, ValueNode forY, NodeView view) {
AddNode self = addNode;
boolean associative = op.isAssociative();
if (associative) {
if (forX instanceof SubNode) {
SubNode sub = (SubNode) forX;
if (sub.getY() == forY) {
// (a - b) + b
return sub.getX();
}
}
if (forY instanceof SubNode) {
SubNode sub = (SubNode) forY;
if (sub.getY() == forX) {
// b + (a - b)
return sub.getX();
}
}
}
if (forY.isConstant()) {
Constant c = forY.asConstant();
if (op.isNeutral(c)) {
return forX;
}
if (associative && self != null) {
// canonicalize expressions like "(a + 1) + 2"
ValueNode reassociated = reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
if (reassociated != self) {
return reassociated;
}
}
}
if (forX instanceof NegateNode) {
return BinaryArithmeticNode.sub(forY, ((NegateNode) forX).getValue(), view);
} else if (forY instanceof NegateNode) {
return BinaryArithmeticNode.sub(forX, ((NegateNode) forY).getValue(), view);
}
if (self == null) {
self = (AddNode) new AddNode(forX, forY).maybeCommuteInputs();
}
return self;
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class AndNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
ValueNode ret = super.canonical(tool, forX, forY);
if (ret != this) {
return ret;
}
NodeView view = NodeView.from(tool);
return canonical(this, getOp(forX, forY), stamp(view), forX, forY, view);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class BinaryArithmeticNode method maybeCommuteInputs.
/**
* Ensure a canonical ordering of inputs for commutative nodes to improve GVN results. Order the
* inputs by increasing {@link Node#id} and call {@link Graph#findDuplicate(Node)} on the node
* if it's currently in a graph. It's assumed that if there was a constant on the left it's been
* moved to the right by other code and that ordering is left alone.
*
* @return the original node or another node with the same input ordering
*/
@SuppressWarnings("deprecation")
public BinaryNode maybeCommuteInputs() {
assert this instanceof BinaryCommutative;
if (!y.isConstant() && (x.isConstant() || x.getId() > y.getId())) {
ValueNode tmp = x;
x = y;
y = tmp;
if (graph() != null) {
// See if this node already exists
BinaryNode duplicate = graph().findDuplicate(this);
if (duplicate != null) {
return duplicate;
}
}
}
return this;
}
Aggregations