Skip to content

Regression: Unnecessary bounds check generated #115793

Open
@rameel

Description

@rameel

Repro: Godbolt

static bool Repro(string prefix, string path)
{
    // ...

    if ((uint)prefix.Length < (uint)path.Length)
        return (path[prefix.Length] == '/');

    return false;
}

trunk-20250520+a78f02b009:

       push     rbp
       mov      rbp, rsp
       mov      ecx, dword ptr [rdi+0x08]
       mov      edx, dword ptr [rsi+0x08]
       cmp      ecx, edx
       jl       SHORT G_M63302_IG05
       xor      eax, eax
       pop      rbp
       ret      
G_M63302_IG05:  ;; offset=0x0012
       cmp      ecx, edx             ; <--- Redundant
       jae      SHORT G_M63302_IG07  ; <---
       mov      eax, ecx
       cmp      word  ptr [rsi+2*rax+0x0C], 47
       sete     al
       movzx    rax, al
       pop      rbp
       ret      
G_M63302_IG07:  ;; offset=0x0026
       call     CORINFO_HELP_RNGCHKFAIL
       int3     

coreclr 9.0.2+80aa709f5d:

       mov      ecx, dword ptr [rdi+0x08]
       mov      eax, dword ptr [rsi+0x08]
       cmp      ecx, eax
       jb       SHORT G_M63302_IG05
       xor      eax, eax
       ret      
G_M63302_IG05:  ;; offset=0x000D
       mov      eax, ecx
       cmp      word  ptr [rsi+2*rax+0x0C], 47
       sete     al
       movzx    rax, al
       ret      

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions