Repository: dotnet/runtime
File: src/coreclr/jit/codegenwasm.cpp (C++)

Code before:
// Arguments
//    tree - the GT_BITCAST for which we're generating code
//
void CodeGen::genCodeForBitCast(GenTreeOp* tree)
{
    assert(tree->OperIs(GT_BITCAST));
    genConsumeOperands(tree);
    assert(tree->TypeGet() == genActualType(tree));

    var_types toType   = tree->TypeGet();
    var_types fromType = tree->gtGetOp1()->TypeGet();

    instruction ins = INS_none;
    switch (PackTypes(fromType, toType))
    {
        case PackTypes(TYP_INT, TYP_FLOAT):
            ins = INS_i32_reinterpret_f32;
            break;
        case PackTypes(TYP_FLOAT, TYP_INT):
            ins = INS_f32_reinterpret_i32;
            break;
        case PackTypes(TYP_LONG, TYP_DOUBLE):
            ins = INS_i64_reinterpret_f64;
            break;
        case PackTypes(TYP_DOUBLE, TYP_LONG):
            ins = INS_f64_reinterpret_i64;
            break;
        default:
            unreached();
            break;
    }

    GetEmitter()->emitIns(ins);
    genProduceReg(tree);
}

//------------------------------------------------------------------------
// genCodeForNegNot: Generate code for a neg/not
//
// Arguments:
//    tree - neg/not tree node
//
void CodeGen::genCodeForNegNot(GenTreeOp* tree)
{
    assert(tree->OperIs(GT_NEG, GT_NOT));
    genConsumeOperands(tree);

    instruction ins;
    switch (PackOperAndType(tree->OperGet(), tree->TypeGet()))
    {
        case PackOperAndType(GT_NOT, TYP_INT):

Review comment (suggestion):
The reinterpret opcodes for the i64<->f64 bitcasts are reversed. `i64.reinterpret_f64` takes an f64 and produces an i64, while `f64.reinterpret_i64` takes an i64 and produces an f64. Please swap the instruction selection so the emitted opcode matches the GT_BITCAST direction (operand type -> result type).
```suggestion
            ins = INS_f32_reinterpret_i32;
            break;
        case PackTypes(TYP_FLOAT, TYP_INT):
            ins = INS_i32_reinterpret_f32;
            break;
        case PackTypes(TYP_LONG, TYP_DOUBLE):
            ins = INS_f64_reinterpret_i64;
            break;
        case PackTypes(TYP_DOUBLE, TYP_LONG):
            ins = INS_i64_reinterpret_f64;
```

Code after:
// Arguments
//    tree - the GT_BITCAST for which we're generating code
//
void CodeGen::genCodeForBitCast(GenTreeOp* tree)
{
    assert(tree->OperIs(GT_BITCAST));
    genConsumeOperands(tree);

    var_types toType   = tree->TypeGet();
    var_types fromType = genActualType(tree->gtGetOp1()->TypeGet());
    assert(toType == genActualType(tree));

    instruction ins = INS_none;
    switch (PackTypes(toType, fromType))
    {
        case PackTypes(TYP_INT, TYP_FLOAT):
            ins = INS_i32_reinterpret_f32;
            break;
        case PackTypes(TYP_FLOAT, TYP_INT):
            ins = INS_f32_reinterpret_i32;
            break;
        case PackTypes(TYP_LONG, TYP_DOUBLE):
            ins = INS_i64_reinterpret_f64;
            break;
        case PackTypes(TYP_DOUBLE, TYP_LONG):
            ins = INS_f64_reinterpret_i64;
            break;
        default:
            unreached();
            break;
    }

    GetEmitter()->emitIns(ins);
    genProduceReg(tree);
}

//------------------------------------------------------------------------
// genCodeForNegNot: Generate code for a neg/not
//
// Arguments:
//    tree - neg/not tree node
//
void CodeGen::genCodeForNegNot(GenTreeOp* tree)
{
    assert(tree->OperIs(GT_NEG, GT_NOT));
    genConsumeOperands(tree);

    instruction ins;
    switch (PackOperAndType(tree->OperGet(), tree->TypeGet()))
    {
        case PackOperAndType(GT_NOT, TYP_INT):