Skip to content

Bound check with uint casts no longer elided #123085

Closed

Description

@MihaZupan
public static int Foo(string str)
{
    int length = str.Length;
    
    while ((uint)(length - 1) < (uint)str.Length && str[length - 1] == ' ')
    {
        length--;
    }
    
    return length;
}

public static int Bar(string str)
{
    int length = str.Length;
    
    while (length > 0 && str[length - 1] == ' ')
    {
        length--;
    }
    
    return length;
}

In .NET 9, Foo elided the extra bounds check, but godbolt is showing it again on main https://godbolt.org/z/qnYEzcdne.

Bar also seems like something where the JIT could prove that an extra check isn't needed.

Activity

  1. added
    area-CodeGen-coreclr
    on Jan 12, 2026
  2. added
    untriaged
    on Jan 12, 2026
  3. dotnet-policy-service commented on Jan 12, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. self-assigned this
    on Jan 12, 2026
  5. added this to the 11.0.0 milestone on Jan 12, 2026
  6. removed
    untriaged
    on Jan 12, 2026
  7. locked and limited conversation to collaborators on Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrreduce-unsafe

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions