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

Code before:

//------------------------------------------------------------------------
// genLclHeap: Generate code for LCLHEAP
//
// Arguments:
//    tree -- LCLHEAP tree
//
// Notes:
//   Codegen varies depending on:
//   * whether the size operand is a constant or not
//   * whether the allocated memory needs to be zeroed or not (info.compInitMem)
//
//   If the sp is changed, the value at sp[0] must be the frame pointer
//   so that the runtime unwinder can locate the base of the fixed area
//   in the shadow stack.
//
void CodeGen::genLclHeap(GenTree* tree)
{
    assert(tree->OperIs(GT_LCLHEAP));
    assert(m_compiler->compLocallocUsed);
    assert(isFramePointerUsed());

    bool const     needsZeroing = m_compiler->info.compInitMem;
    GenTree* const size         = tree->AsOp()->gtOp1;

    assert(genActualType(size->gtType) == TYP_I_IMPL);

    // We reserve this amount of space below any allocation for
    // establishing unwind invariants.
    //
    size_t const reservedSpace = STACK_ALIGN;

    // Constant LCLHEAP size operands are contained by lower.
    //
    if (size->isContainedIntOrIImmed())
    {
        size_t amount = size->AsIntCon()->gtIconVal;

        // Handle zero
        //
        if (amount == 0)
        {
            GetEmitter()->emitIns_I(INS_I_const, EA_PTRSIZE, 0);
        }
        else
        {
            // Add in the reserved space and round up.
            //
            amount = AlignUp(amount + reservedSpace, STACK_ALIGN);

            // Decrease the stack pointer by amount

Review comment (suggestion):
```suggestion
    assert(genActualType(size) == TYP_I_IMPL);
```

Code after:
{
    assert(tree->OperIsCmpCompare());

    GenTree* const  op1     = tree->gtGetOp1();
    var_types const op1Type = op1->TypeGet();

    if (varTypeIsFloating(op1Type))
    {
        genCompareFloat(tree);
    }
    else
    {
        genCompareInt(tree);
    }
}

//------------------------------------------------------------------------
// genCompareInt: Generate code for comparing ints or longs
//
// Arguments:
//    treeNode - the compare tree
//
void CodeGen::genCompareInt(GenTreeOp* treeNode)
{
    assert(treeNode->OperIsCmpCompare());
    genConsumeOperands(treeNode);

    instruction ins;
    switch (PackOperAndType(treeNode->OperGet(), genActualType(treeNode->gtGetOp1()->TypeGet())))
    {
        case PackOperAndType(GT_EQ, TYP_INT):
            ins = INS_i32_eq;
            break;
        case PackOperAndType(GT_EQ, TYP_LONG):
            ins = INS_i64_eq;
            break;
        case PackOperAndType(GT_NE, TYP_INT):
            ins = INS_i32_ne;
            break;
        case PackOperAndType(GT_NE, TYP_LONG):
            ins = INS_i64_ne;
            break;
        case PackOperAndType(GT_LT, TYP_INT):
            ins = treeNode->IsUnsigned() ? INS_i32_lt_u : INS_i32_lt_s;
            break;
        case PackOperAndType(GT_LT, TYP_LONG):
            ins = treeNode->IsUnsigned() ? INS_i64_lt_u : INS_i64_lt_s;
            break;
        case PackOperAndType(GT_LE, TYP_INT):
            ins = treeNode->IsUnsigned() ? INS_i32_le_u : INS_i32_le_s;
            break;