use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class AMD64AddressLowering method improveNegation.
private boolean improveNegation(StructuredGraph graph, DebugContext debug, AMD64AddressNode ret, boolean originalBaseNegated, boolean originalIndexNegated) {
boolean baseNegated = originalBaseNegated;
boolean indexNegated = originalIndexNegated;
ValueNode originalBase = ret.getBase();
ValueNode originalIndex = ret.getIndex();
if (ret.getBase() instanceof NegateNode) {
NegateNode negate = (NegateNode) ret.getBase();
ret.setBase(negate.getValue());
baseNegated = !baseNegated;
}
if (ret.getIndex() instanceof NegateNode) {
NegateNode negate = (NegateNode) ret.getIndex();
ret.setIndex(negate.getValue());
indexNegated = !indexNegated;
}
if (baseNegated != originalBaseNegated || indexNegated != originalIndexNegated) {
ValueNode base = ret.getBase();
ValueNode index = ret.getIndex();
boolean improved = improve(graph, debug, ret, baseNegated, indexNegated);
if (baseNegated != originalBaseNegated) {
if (base == ret.getBase()) {
ret.setBase(originalBase);
} else if (ret.getBase() != null) {
ret.setBase(graph.maybeAddOrUnique(NegateNode.create(ret.getBase(), NodeView.DEFAULT)));
}
}
if (indexNegated != originalIndexNegated) {
if (index == ret.getIndex()) {
ret.setIndex(originalIndex);
} else if (ret.getIndex() != null) {
ret.setIndex(graph.maybeAddOrUnique(NegateNode.create(ret.getIndex(), NodeView.DEFAULT)));
}
}
return improved;
} else {
assert ret.getBase() == originalBase && ret.getIndex() == originalIndex;
}
return false;
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class ShiftNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
ValueNode valueNode = canonical(getOp(forX), stamp(NodeView.DEFAULT), forX, forY, view);
if (valueNode != null) {
return valueNode;
}
return this;
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class SignExtendNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool, ValueNode forValue) {
NodeView view = NodeView.from(tool);
ValueNode ret = super.canonical(tool, forValue);
if (ret != this) {
return ret;
}
return canonical(this, forValue, getInputBits(), getResultBits(), view);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class SubNode method canonical.
private static ValueNode canonical(SubNode subNode, BinaryOp<Sub> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
SubNode self = subNode;
if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
Constant zero = op.getZero(forX.stamp(view));
if (zero != null) {
return ConstantNode.forPrimitive(stamp, zero);
}
}
boolean associative = op.isAssociative();
if (associative) {
if (forX instanceof AddNode) {
AddNode x = (AddNode) forX;
if (x.getY() == forY) {
// (a + b) - b
return x.getX();
}
if (x.getX() == forY) {
// (a + b) - a
return x.getY();
}
} else if (forX instanceof SubNode) {
SubNode x = (SubNode) forX;
if (x.getX() == forY) {
// (a - b) - a
return NegateNode.create(x.getY(), view);
}
}
if (forY instanceof AddNode) {
AddNode y = (AddNode) forY;
if (y.getX() == forX) {
// a - (a + b)
return NegateNode.create(y.getY(), view);
}
if (y.getY() == forX) {
// b - (a + b)
return NegateNode.create(y.getX(), view);
}
} else if (forY instanceof SubNode) {
SubNode y = (SubNode) forY;
if (y.getX() == forX) {
// a - (a - b)
return y.getY();
}
}
}
if (forY.isConstant()) {
Constant c = forY.asConstant();
if (op.isNeutral(c)) {
return forX;
}
if (associative && self != null) {
ValueNode reassociated = reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
if (reassociated != self) {
return reassociated;
}
}
if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
long i = ((PrimitiveConstant) c).asLong();
if (i < 0 || ((IntegerStamp) StampFactory.forKind(forY.getStackKind())).contains(-i)) {
// commutative, so prefer add when it fits.
return BinaryArithmeticNode.add(forX, ConstantNode.forIntegerStamp(stamp, -i), view);
}
}
} else if (forX.isConstant()) {
Constant c = forX.asConstant();
if (ArithmeticOpTable.forStamp(stamp).getAdd().isNeutral(c)) {
/*
* Note that for floating point numbers, + and - have different neutral elements. We
* have to test for the neutral element of +, because we are doing this
* transformation: 0 - x == (-x) + 0 == -x.
*/
return NegateNode.create(forY, view);
}
if (associative && self != null) {
return reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
}
}
if (forY instanceof NegateNode) {
return BinaryArithmeticNode.add(forX, ((NegateNode) forY).getValue(), view);
}
return self != null ? self : new SubNode(forX, forY);
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class SubNode 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;
}
BinaryOp<Sub> op = getOp(forX, forY);
return canonical(this, op, stamp, forX, forY, view);
}
Aggregations