Search in sources :

Example 1 with CondSetOp

use of org.graalvm.compiler.lir.amd64.AMD64ControlFlow.CondSetOp in project graal by oracle.

the class AMD64LIRGenerator method emitConditionalMove.

@Override
public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) {
    boolean isFloatComparison = cmpKind == AMD64Kind.SINGLE || cmpKind == AMD64Kind.DOUBLE;
    Condition finalCondition = cond;
    Value finalTrueValue = trueValue;
    Value finalFalseValue = falseValue;
    if (isFloatComparison) {
        // eliminate the parity check in case of a float comparison
        Value finalLeft = left;
        Value finalRight = right;
        if (unorderedIsTrue != AMD64ControlFlow.trueOnUnordered(finalCondition)) {
            if (unorderedIsTrue == AMD64ControlFlow.trueOnUnordered(finalCondition.mirror())) {
                finalCondition = finalCondition.mirror();
                finalLeft = right;
                finalRight = left;
            } else if (finalCondition != Condition.EQ && finalCondition != Condition.NE) {
                // NaN semantics)
                assert unorderedIsTrue == AMD64ControlFlow.trueOnUnordered(finalCondition.negate());
                finalCondition = finalCondition.negate();
                finalTrueValue = falseValue;
                finalFalseValue = trueValue;
            }
        }
        emitRawCompare(cmpKind, finalLeft, finalRight);
    } else {
        finalCondition = emitCompare(cmpKind, left, right, cond);
    }
    boolean isParityCheckNecessary = isFloatComparison && unorderedIsTrue != AMD64ControlFlow.trueOnUnordered(finalCondition);
    Variable result = newVariable(finalTrueValue.getValueKind());
    if (!isParityCheckNecessary && isIntConstant(finalTrueValue, 1) && isIntConstant(finalFalseValue, 0)) {
        if (isFloatComparison) {
            append(new FloatCondSetOp(result, finalCondition));
        } else {
            append(new CondSetOp(result, finalCondition));
        }
    } else if (!isParityCheckNecessary && isIntConstant(finalTrueValue, 0) && isIntConstant(finalFalseValue, 1)) {
        if (isFloatComparison) {
            if (unorderedIsTrue == AMD64ControlFlow.trueOnUnordered(finalCondition.negate())) {
                append(new FloatCondSetOp(result, finalCondition.negate()));
            } else {
                append(new FloatCondSetOp(result, finalCondition));
                Variable negatedResult = newVariable(result.getValueKind());
                append(new AMD64Binary.ConstOp(AMD64BinaryArithmetic.XOR, OperandSize.get(result.getPlatformKind()), negatedResult, result, 1));
                result = negatedResult;
            }
        } else {
            append(new CondSetOp(result, finalCondition.negate()));
        }
    } else if (isFloatComparison) {
        append(new FloatCondMoveOp(result, finalCondition, unorderedIsTrue, load(finalTrueValue), load(finalFalseValue)));
    } else {
        append(new CondMoveOp(result, finalCondition, load(finalTrueValue), loadNonConst(finalFalseValue)));
    }
    return result;
}
Also used : Condition(org.graalvm.compiler.core.common.calc.Condition) Variable(org.graalvm.compiler.lir.Variable) FloatCondSetOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatCondSetOp) LIRValueUtil.asConstantValue(org.graalvm.compiler.lir.LIRValueUtil.asConstantValue) ConstantValue(org.graalvm.compiler.lir.ConstantValue) LIRValueUtil.isConstantValue(org.graalvm.compiler.lir.LIRValueUtil.isConstantValue) Value(jdk.vm.ci.meta.Value) ValueUtil.isAllocatableValue(jdk.vm.ci.code.ValueUtil.isAllocatableValue) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) RegisterValue(jdk.vm.ci.code.RegisterValue) AMD64AddressValue(org.graalvm.compiler.lir.amd64.AMD64AddressValue) CondMoveOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.CondMoveOp) FloatCondMoveOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatCondMoveOp) FloatCondMoveOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatCondMoveOp) CondSetOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.CondSetOp) FloatCondSetOp(org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatCondSetOp)

Aggregations

RegisterValue (jdk.vm.ci.code.RegisterValue)1 ValueUtil.isAllocatableValue (jdk.vm.ci.code.ValueUtil.isAllocatableValue)1 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 Value (jdk.vm.ci.meta.Value)1 Condition (org.graalvm.compiler.core.common.calc.Condition)1 ConstantValue (org.graalvm.compiler.lir.ConstantValue)1 LIRValueUtil.asConstantValue (org.graalvm.compiler.lir.LIRValueUtil.asConstantValue)1 LIRValueUtil.isConstantValue (org.graalvm.compiler.lir.LIRValueUtil.isConstantValue)1 Variable (org.graalvm.compiler.lir.Variable)1 AMD64AddressValue (org.graalvm.compiler.lir.amd64.AMD64AddressValue)1 CondMoveOp (org.graalvm.compiler.lir.amd64.AMD64ControlFlow.CondMoveOp)1 CondSetOp (org.graalvm.compiler.lir.amd64.AMD64ControlFlow.CondSetOp)1 FloatCondMoveOp (org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatCondMoveOp)1 FloatCondSetOp (org.graalvm.compiler.lir.amd64.AMD64ControlFlow.FloatCondSetOp)1