Search in sources :

Example 1 with ADD

use of org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.ADD in project graal by oracle.

the class AMD64NodeMatchRules method addMemory.

@MatchRule("(Add value Read=access)")
@MatchRule("(Add value FloatingRead=access)")
public ComplexMatchResult addMemory(ValueNode value, LIRLowerableAccess access) {
    OperandSize size = getMemorySize(access);
    if (size.isXmmType()) {
        TargetDescription target = getLIRGeneratorTool().target();
        boolean isAvx = ((AMD64) target.arch).getFeatures().contains(CPUFeature.AVX);
        if (isAvx) {
            return binaryRead(AVXOp.ADD, size, value, access);
        } else {
            return binaryRead(SSEOp.ADD, size, value, access);
        }
    } else {
        return binaryRead(ADD.getRMOpcode(size), size, value, access);
    }
}
Also used : TargetDescription(jdk.vm.ci.code.TargetDescription) OperandSize(org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize) MatchRule(org.graalvm.compiler.core.match.MatchRule)

Example 2 with ADD

use of org.graalvm.compiler.asm.amd64.AMD64Assembler.AMD64BinaryArithmetic.ADD in project graal by oracle.

the class AMD64AddressLowering method improve.

/**
 * Tries to optimize addresses so that they match the AMD64-specific addressing mode better
 * (base + index * scale + displacement).
 *
 * @param graph the current graph
 * @param debug the current debug context
 * @param ret the address that should be optimized
 * @param isBaseNegated determines if the address base is negated. if so, all values that are
 *            extracted from the base will be negated as well
 * @param isIndexNegated determines if the index is negated. if so, all values that are
 *            extracted from the index will be negated as well
 * @return true if the address was modified
 */
protected boolean improve(StructuredGraph graph, DebugContext debug, AMD64AddressNode ret, boolean isBaseNegated, boolean isIndexNegated) {
    ValueNode newBase = improveInput(ret, ret.getBase(), 0, isBaseNegated);
    if (newBase != ret.getBase()) {
        ret.setBase(newBase);
        return true;
    }
    ValueNode newIdx = improveInput(ret, ret.getIndex(), ret.getScale().log2, isIndexNegated);
    if (newIdx != ret.getIndex()) {
        ret.setIndex(newIdx);
        return true;
    }
    if (ret.getIndex() instanceof LeftShiftNode) {
        LeftShiftNode shift = (LeftShiftNode) ret.getIndex();
        if (shift.getY().isConstant()) {
            int amount = ret.getScale().log2 + shift.getY().asJavaConstant().asInt();
            Scale scale = Scale.fromShift(amount);
            if (scale != null) {
                ret.setIndex(shift.getX());
                ret.setScale(scale);
                return true;
            }
        }
    }
    if (ret.getScale() == Scale.Times1) {
        if (ret.getIndex() == null && ret.getBase() instanceof AddNode) {
            AddNode add = (AddNode) ret.getBase();
            ret.setBase(add.getX());
            ret.setIndex(considerNegation(graph, add.getY(), isBaseNegated));
            return true;
        }
        if (ret.getBase() == null && ret.getIndex() instanceof AddNode) {
            AddNode add = (AddNode) ret.getIndex();
            ret.setBase(considerNegation(graph, add.getX(), isIndexNegated));
            ret.setIndex(add.getY());
            return true;
        }
        if (ret.getBase() instanceof LeftShiftNode && !(ret.getIndex() instanceof LeftShiftNode)) {
            ValueNode tmp = ret.getBase();
            ret.setBase(considerNegation(graph, ret.getIndex(), isIndexNegated != isBaseNegated));
            ret.setIndex(considerNegation(graph, tmp, isIndexNegated != isBaseNegated));
            return true;
        }
    }
    return improveNegation(graph, debug, ret, isBaseNegated, isIndexNegated);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) Scale(org.graalvm.compiler.asm.amd64.AMD64Address.Scale) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Aggregations

TargetDescription (jdk.vm.ci.code.TargetDescription)1 Scale (org.graalvm.compiler.asm.amd64.AMD64Address.Scale)1 OperandSize (org.graalvm.compiler.asm.amd64.AMD64Assembler.OperandSize)1 MatchRule (org.graalvm.compiler.core.match.MatchRule)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 AddNode (org.graalvm.compiler.nodes.calc.AddNode)1 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)1