Skip to content

Unnecessary overflow check with checked on 64-bit ryujit #111567

@hamarb123

Description

@hamarb123

Description

Elidable checked is not elided.

/cc @EgorBo who asked me to open an issue for it

Configuration

64-bit on sharplab.com

Regression?

Probably not.

Data

public class C {
    public nuint M(uint a) {
        return checked((nuint)a * 8);
    }
}

gives

C.M(UInt32)
    L0000: sub rsp, 0x28
    L0004: mov eax, edx
    L0006: mov ecx, 8
    L000b: mul rcx
    L000e: jb short L0015
    L0010: add rsp, 0x28
    L0014: ret
    L0015: call 0x0000027c46350090
    L001a: int3

Sharplab link

Analysis

The checked can be elided on 64-bit, since a fits within 32 bits & a * 8 fits within 35 bits, which means no overflow can occur with 64-bits of storage.

Seemingly doesn't reproduce on 32-bit when nuint is replaced with ulong (but still does on 64-bit)? Sharplab link

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions