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

Code before:
    genProduceReg(treeNode);
}

//----------------------------------------------------------------------
// genCodeForBitCast - Generate code for a GT_BITCAST that is not contained
//
// 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));

Review comment (suggestion):
The reinterpret opcodes for the i32<->f32 bitcasts are reversed. `i32.reinterpret_f32` takes an f32 and produces an i32, while `f32.reinterpret_i32` takes an i32 and produces an f32. 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;
```

Code after:
    genProduceReg(treeNode);
}

//----------------------------------------------------------------------
// genCodeForBitCast - Generate code for a GT_BITCAST that is not contained
//
// 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));