use of org.graalvm.compiler.nodes.calc.NegateNode in project graal by oracle.
the class AMD64AddressLoweringTest method convertBaseAndNegatedShiftedIndexToDisplacement.
@Test
public void convertBaseAndNegatedShiftedIndexToDisplacement() {
ValueNode base = graph.addOrUniqueWithInputs(const64(1000));
ValueNode index = graph.addOrUniqueWithInputs(new NegateNode(new LeftShiftNode(const64(10), const32(2))));
AddressNode result = lowering.lower(base, index);
assertAddress(result, null, null, Scale.Times4, 960);
}
use of org.graalvm.compiler.nodes.calc.NegateNode 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.calc.NegateNode in project graal by oracle.
the class LoopEx method findInductionVariables.
/**
* Collect all the basic induction variables for the loop and the find any induction variables
* which are derived from the basic ones.
*
* @param loop
* @return a map from node to induction variable
*/
private static EconomicMap<Node, InductionVariable> findInductionVariables(LoopEx loop) {
EconomicMap<Node, InductionVariable> ivs = EconomicMap.create(Equivalence.IDENTITY);
Queue<InductionVariable> scanQueue = new LinkedList<>();
LoopBeginNode loopBegin = loop.loopBegin();
AbstractEndNode forwardEnd = loopBegin.forwardEnd();
for (PhiNode phi : loopBegin.valuePhis()) {
ValueNode backValue = phi.singleBackValueOrThis();
if (backValue == phi) {
continue;
}
ValueNode stride = addSub(loop, backValue, phi);
if (stride != null) {
BasicInductionVariable biv = new BasicInductionVariable(loop, (ValuePhiNode) phi, phi.valueAt(forwardEnd), stride, (BinaryArithmeticNode<?>) backValue);
ivs.put(phi, biv);
scanQueue.add(biv);
}
}
while (!scanQueue.isEmpty()) {
InductionVariable baseIv = scanQueue.remove();
ValueNode baseIvNode = baseIv.valueNode();
for (ValueNode op : baseIvNode.usages().filter(ValueNode.class)) {
if (loop.isOutsideLoop(op)) {
continue;
}
if (op.usages().count() == 1 && op.usages().first() == baseIvNode) {
/*
* This is just the base induction variable increment with no other uses so
* don't bother reporting it.
*/
continue;
}
InductionVariable iv = null;
ValueNode offset = addSub(loop, op, baseIvNode);
ValueNode scale;
if (offset != null) {
iv = new DerivedOffsetInductionVariable(loop, baseIv, offset, (BinaryArithmeticNode<?>) op);
} else if (op instanceof NegateNode) {
iv = new DerivedScaledInductionVariable(loop, baseIv, (NegateNode) op);
} else if ((scale = mul(loop, op, baseIvNode)) != null) {
iv = new DerivedScaledInductionVariable(loop, baseIv, scale, op);
} else {
boolean isValidConvert = op instanceof PiNode || op instanceof SignExtendNode;
if (!isValidConvert && op instanceof ZeroExtendNode) {
ZeroExtendNode zeroExtendNode = (ZeroExtendNode) op;
isValidConvert = zeroExtendNode.isInputAlwaysPositive() || ((IntegerStamp) zeroExtendNode.stamp(NodeView.DEFAULT)).isPositive();
}
if (isValidConvert) {
iv = new DerivedConvertedInductionVariable(loop, baseIv, op.stamp(NodeView.DEFAULT), op);
}
}
if (iv != null) {
ivs.put(op, iv);
scanQueue.offer(iv);
}
}
}
return ivs;
}
use of org.graalvm.compiler.nodes.calc.NegateNode in project graal by oracle.
the class AMD64AddressLoweringTest method convertNegatedBaseAndNegatedShiftedIndexToDisplacement.
@Test
public void convertNegatedBaseAndNegatedShiftedIndexToDisplacement() {
ValueNode base = graph.addOrUniqueWithInputs(new NegateNode(const64(1000)));
ValueNode index = graph.addOrUniqueWithInputs(new NegateNode(new LeftShiftNode(const64(10), const32(2))));
AddressNode result = lowering.lower(base, index);
assertAddress(result, null, null, Scale.Times4, -1040);
}
use of org.graalvm.compiler.nodes.calc.NegateNode in project graal by oracle.
the class AMD64AddressLoweringTest method convertNegatedShiftedBaseAndNegatedIndexToDisplacement.
@Test
public void convertNegatedShiftedBaseAndNegatedIndexToDisplacement() {
ValueNode base = graph.addOrUniqueWithInputs(new NegateNode(new LeftShiftNode(const64(10), const32(2))));
ValueNode index = graph.addOrUniqueWithInputs(new NegateNode(const64(1000)));
AddressNode result = lowering.lower(base, index);
assertAddress(result, null, null, Scale.Times4, -1040);
}
Aggregations