Eliminate bound checks for "arr[arr.Length - cns]" by EgorBo · Pull Request #84213 · dotnet/runtime

; Method Test1(int[]):this
       sub      rsp, 40
       mov      eax, dword ptr [rdx+08H]
       test     eax, eax
       je       SHORT G_M32023_IG04
       lea      ecx, [rax-01H]
       cmp      ecx, eax
       jae      SHORT G_M32023_IG06
       mov      eax, ecx
       cmp      dword ptr [rdx+4*rax+10H], 0
       jne      SHORT G_M32023_IG05
G_M32023_IG04:
       add      rsp, 40
       tail.jmp [System.Console:WriteLine()]
G_M32023_IG05:
       add      rsp, 40
       ret      
G_M32023_IG06:
       call     CORINFO_HELP_RNGCHKFAIL
       int3     
; Total bytes of code: 48


; Method Test2(int[]):this
       sub      rsp, 40
       mov      eax, dword ptr [rdx+08H]
       cmp      eax, 10
       jge      SHORT G_M54292_IG04
       add      rsp, 40
       ret      
G_M54292_IG04:
       lea      ecx, [rax-0AH]
       cmp      ecx, eax
       jae      SHORT G_M54292_IG07
       mov      eax, ecx
       cmp      dword ptr [rdx+4*rax+10H], 0
       jne      SHORT G_M54292_IG06
       add      rsp, 40
       tail.jmp [System.Console:WriteLine()]
G_M54292_IG06:
       add      rsp, 40
       ret      
G_M54292_IG07:
       call     CORINFO_HELP_RNGCHKFAIL
       int3     
; Total bytes of code: 54
; Method Test1(int[]):this
       mov      eax, dword ptr [rdx+08H]
       test     eax, eax
       je       SHORT G_M32023_IG04
       dec      eax
       cmp      dword ptr [rdx+4*rax+10H], 0
       jne      SHORT G_M32023_IG05
G_M32023_IG04:
       tail.jmp [System.Console:WriteLine()]
G_M32023_IG05:
       ret      
; Total bytes of code: 23


; Method Test2(int[]):this
       mov      eax, dword ptr [rdx+08H]
       cmp      eax, 10
       jge      SHORT G_M54292_IG04
       ret      
G_M54292_IG04:
       add      eax, -10
       cmp      dword ptr [rdx+4*rax+10H], 0
       jne      SHORT G_M54292_IG06
       tail.jmp [System.Console:WriteLine()]
G_M54292_IG06:
       ret      
; Total bytes of code: 26