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

Code before:
                // TODO-WASM-CQ: possibly do small fills directly
                //
                GetEmitter()->emitIns_I(INS_memory_fill, EA_4BYTE, LINEAR_MEMORY_INDEX);
            }

            // SP now points at the reserved space just below the allocation.
            // Save the frame pointer at sp[0].
            //
            GetEmitter()->emitIns_I(INS_local_get, EA_PTRSIZE, WasmRegToIndex(GetStackPointerReg()));
            GetEmitter()->emitIns_I(INS_local_get, EA_PTRSIZE, WasmRegToIndex(GetFramePointerReg()));
            GetEmitter()->emitIns_I(ins_Store(TYP_I_IMPL), EA_PTRSIZE, 0);

            // Leave the base address of the allocated region on the stack.
            //
            GetEmitter()->emitIns_I(INS_local_get, EA_PTRSIZE, WasmRegToIndex(GetStackPointerReg()));
            GetEmitter()->emitIns_I(INS_I_const, EA_PTRSIZE, reservedSpace);
            GetEmitter()->emitIns(INS_I_add);
        }
    }
    else
    {
        bool const is64Bit = (TARGET_POINTER_SIZE == 8);
        genConsumeReg(size);

        // Extend size to pointer size, if necessary
        if (genTypeSize(size->TypeGet()) < TARGET_POINTER_SIZE)
        {
            assert(TARGET_POINTER_SIZE == 8);
            GetEmitter()->emitIns(INS_i64_extend_u_i32);
        }

        // Fetch the internal register we reserved during RA
        InternalRegs* regs = internalRegisters.GetAll(tree);
        assert(regs->Count() == 1);
        regNumber sizeReg = regs->Extract();
        assert(WasmRegToType(sizeReg) == TypeToWasmValueType(TYP_I_IMPL));

        // Check for zero-sized requests
        GetEmitter()->emitIns(INS_I_eqz);
        GetEmitter()->emitIns_Block_Ty(INS_if, is64Bit ? WasmValueType::I64 : WasmValueType::I32);
        {
            // If size is zero, leave a zero on the stack
            GetEmitter()->emitIns_I(INS_I_const, EA_PTRSIZE, 0);
        }
        // Else ... nonzero size case.
        GetEmitter()->emitIns(INS_else);
        {
            // Prepare to subtract from SP
            GetEmitter()->emitIns_I(INS_local_get, EA_PTRSIZE, WasmRegToIndex(GetStackPointerReg()));

            // Add reserved space and round up request size to a multiple of STACK_ALIGN

Review comment (suggestion):
```suggestion
        if (genTypeSize(genActualType(size)) < TARGET_POINTER_SIZE)
```

Code after:
                // TODO-WASM-CQ: possibly do small fills directly
                //
                GetEmitter()->emitIns_I(INS_memory_fill, EA_4BYTE, LINEAR_MEMORY_INDEX);
            }

            // SP now points at the reserved space just below the allocation.
            // Save the frame pointer at sp[0].
            //
            GetEmitter()->emitIns_I(INS_local_get, EA_PTRSIZE, WasmRegToIndex(GetStackPointerReg()));
            GetEmitter()->emitIns_I(INS_local_get, EA_PTRSIZE, WasmRegToIndex(GetFramePointerReg()));
            GetEmitter()->emitIns_I(ins_Store(TYP_I_IMPL), EA_PTRSIZE, 0);

            // Leave the base address of the allocated region on the stack.
            //
            GetEmitter()->emitIns_I(INS_local_get, EA_PTRSIZE, WasmRegToIndex(GetStackPointerReg()));
            GetEmitter()->emitIns_I(INS_I_const, EA_PTRSIZE, reservedSpace);
            GetEmitter()->emitIns(INS_I_add);
        }
    }
    else
    {
        bool const is64Bit = (TARGET_POINTER_SIZE == 8);
        genConsumeReg(size);

        // Extend size to pointer size, if necessary
        if (genTypeSize(genActualType(size->TypeGet())) < TARGET_POINTER_SIZE)
        {
            assert(TARGET_POINTER_SIZE == 8);
            GetEmitter()->emitIns(INS_i64_extend_u_i32);
        }

        // Fetch the internal register we reserved during RA
        InternalRegs* regs = internalRegisters.GetAll(tree);
        assert(regs->Count() == 1);
        regNumber sizeReg = regs->Extract();
        assert(WasmRegToType(sizeReg) == TypeToWasmValueType(TYP_I_IMPL));

        // Save the size
        GetEmitter()->emitIns_I(INS_local_tee, EA_PTRSIZE, WasmRegToIndex(sizeReg));

        // Check for zero-sized requests
        GetEmitter()->emitIns(INS_I_eqz);
        GetEmitter()->emitIns_BlockTy(INS_if, is64Bit ? WasmValueType::I64 : WasmValueType::I32);
        {
            // If size is zero, leave a zero on the stack
            GetEmitter()->emitIns_I(INS_I_const, EA_PTRSIZE, 0);
        }
        // Else ... nonzero size case.
        GetEmitter()->emitIns(INS_else);
        {
            // Prepare to subtract from SP