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

Code before:
        m_extendKind = SIGN_EXTEND_INT;
#else
        m_extendKind = COPY;
#endif
        m_extendSrcSize = 4;
    }
#endif
    else // if (castSize == srcSize) // Sign changing or same type cast
    {
        assert(castSize == srcSize);

        if (overflow && (srcUnsigned != castUnsigned))
        {
            m_checkKind    = CHECK_POSITIVE;
            m_checkSrcSize = srcSize;
        }
        else
        {
            m_checkKind = CHECK_NONE;
        }

        m_extendKind    = COPY;
        m_extendSrcSize = srcSize;
    }

#ifndef TARGET_WASM
    if (castIsLoad)
    {
        const var_types srcLoadType = src->TypeGet();

        switch (m_extendKind)
        {
            case ZERO_EXTEND_SMALL_INT: // small type/int/long -> ubyte/ushort
                assert(varTypeIsUnsigned(srcLoadType) || (genTypeSize(srcLoadType) >= genTypeSize(castType)));
                m_extendKind    = LOAD_ZERO_EXTEND_SMALL_INT;
                m_extendSrcSize = min(genTypeSize(srcLoadType), genTypeSize(castType));
                break;

            case SIGN_EXTEND_SMALL_INT: // small type/int/long -> byte/short
                assert(varTypeIsSigned(srcLoadType) || (genTypeSize(srcLoadType) >= genTypeSize(castType)));
                m_extendKind    = LOAD_SIGN_EXTEND_SMALL_INT;
                m_extendSrcSize = min(genTypeSize(srcLoadType), genTypeSize(castType));
                break;

#ifdef TARGET_64BIT
            case ZERO_EXTEND_INT: // ubyte/ushort/uint -> long.
                assert(varTypeIsUnsigned(srcLoadType) || (srcLoadType == TYP_INT));
                m_extendKind    = varTypeIsSmall(srcLoadType) ? LOAD_ZERO_EXTEND_SMALL_INT : LOAD_ZERO_EXTEND_INT;
                m_extendSrcSize = genTypeSize(srcLoadType);
                break;


Review comment (suggestion):
Do you need this ifdef? I think things will work correctly without it (since we don't actually do any containment for casts yet).

Code after:
        m_extendKind = SIGN_EXTEND_INT;
#else
        m_extendKind = COPY;
#endif
        m_extendSrcSize = 4;
    }
#endif
    else // if (castSize == srcSize) // Sign changing or same type cast
    {
        assert(castSize == srcSize);

        if (overflow && (srcUnsigned != castUnsigned))
        {
            m_checkKind    = CHECK_POSITIVE;
            m_checkSrcSize = srcSize;
        }
        else
        {
            m_checkKind = CHECK_NONE;
        }

        m_extendKind    = COPY;
        m_extendSrcSize = srcSize;
    }

    if (castIsLoad)
    {
        const var_types srcLoadType = src->TypeGet();

        switch (m_extendKind)
        {
            case ZERO_EXTEND_SMALL_INT: // small type/int/long -> ubyte/ushort
                assert(varTypeIsUnsigned(srcLoadType) || (genTypeSize(srcLoadType) >= genTypeSize(castType)));
                m_extendKind    = LOAD_ZERO_EXTEND_SMALL_INT;
                m_extendSrcSize = min(genTypeSize(srcLoadType), genTypeSize(castType));
                break;

            case SIGN_EXTEND_SMALL_INT: // small type/int/long -> byte/short
                assert(varTypeIsSigned(srcLoadType) || (genTypeSize(srcLoadType) >= genTypeSize(castType)));
                m_extendKind    = LOAD_SIGN_EXTEND_SMALL_INT;
                m_extendSrcSize = min(genTypeSize(srcLoadType), genTypeSize(castType));
                break;

#ifdef TARGET_64BIT
            case ZERO_EXTEND_INT: // ubyte/ushort/uint -> long.
                assert(varTypeIsUnsigned(srcLoadType) || (srcLoadType == TYP_INT));
                m_extendKind    = varTypeIsSmall(srcLoadType) ? LOAD_ZERO_EXTEND_SMALL_INT : LOAD_ZERO_EXTEND_INT;
                m_extendSrcSize = genTypeSize(srcLoadType);
                break;

            case SIGN_EXTEND_INT: // byte/short/int -> long.