Search in sources :

Example 1 with NegateNode

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);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 2 with NegateNode

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;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode)

Example 3 with NegateNode

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;
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ValueAnchorNode(org.graalvm.compiler.nodes.extended.ValueAnchorNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) IntegerLessThanNode(org.graalvm.compiler.nodes.calc.IntegerLessThanNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) FullInfopointNode(org.graalvm.compiler.nodes.FullInfopointNode) MulNode(org.graalvm.compiler.nodes.calc.MulNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) SubNode(org.graalvm.compiler.nodes.calc.SubNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) PiNode(org.graalvm.compiler.nodes.PiNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) BinaryArithmeticNode(org.graalvm.compiler.nodes.calc.BinaryArithmeticNode) LinkedList(java.util.LinkedList) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode)

Example 4 with NegateNode

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);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 5 with NegateNode

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);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)6 NegateNode (org.graalvm.compiler.nodes.calc.NegateNode)6 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)5 AMD64AddressNode (org.graalvm.compiler.core.amd64.AMD64AddressNode)4 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)4 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)4 Test (org.junit.Test)4 AddNode (org.graalvm.compiler.nodes.calc.AddNode)2 LinkedList (java.util.LinkedList)1 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)1 Node (org.graalvm.compiler.graph.Node)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)1 FixedNode (org.graalvm.compiler.nodes.FixedNode)1 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)1 FullInfopointNode (org.graalvm.compiler.nodes.FullInfopointNode)1 IfNode (org.graalvm.compiler.nodes.IfNode)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1