Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RBO: "X < Y" means "X + 1 <= Y" #113004

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

RBO: "X < Y" means "X + 1 <= Y" #113004

wants to merge 3 commits into from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Feb 28, 2025

Closes #112953

public static ReadOnlySpan<char> Test(ReadOnlySpan<char> span, int offset)
{
    if ((uint)offset < (uint)span.Length)
        return span.Slice(offset + 1);
    return span;
}

Codegen diff:

; Method Program:Test(System.ReadOnlySpan`1[ushort],int):System.ReadOnlySpan`1[ushort] (FullOpts)
-      sub      rsp, 40
       mov      rax, bword ptr [rdx]
       mov      edx, dword ptr [rdx+0x08]
       cmp      r8d, edx
       jb       SHORT G_M39302_IG04
       mov      bword ptr [rcx], rax
       mov      dword ptr [rcx+0x08], edx
       jmp      SHORT G_M39302_IG05
G_M39302_IG04:
       inc      r8d
-      cmp      r8d, edx
-      ja       SHORT G_M39302_IG07
       mov      r10d, r8d
       lea      rax, bword ptr [rax+2*r10]
       sub      edx, r8d
       mov      bword ptr [rcx], rax
       mov      dword ptr [rcx+0x08], edx
G_M39302_IG05:
       mov      rax, rcx
-      add      rsp, 40
       ret      
-G_M39302_IG07:
-      call     [System.ThrowHelper:ThrowArgumentOutOfRangeException()]
-      int3     
-; Total bytes of code: 62
+; Total bytes of code: 42

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JIT can't elide span.Slice range checks after a manual check
1 participant