Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Nov 1, 2025

Closes #121259

When we already have, say, [1..10] range for X and we encounter X != 1 assertion, we can tighten the range to [2..10]

Removes bounds checks for the following snippet:

void Test(ReadOnlySpan<char> name)
{
    if (name is [] or [':'] or [':', not ':', ..])
    {
        Console.WriteLine("test");
    }    
}

Diffs

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Nov 1, 2025
@EgorBo EgorBo marked this pull request as ready for review November 2, 2025 01:28
Copilot AI review requested due to automatic review settings November 2, 2025 01:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances the JIT's range check optimization by adding logic to handle not-equal (!=) assertions. The change allows the optimizer to tighten ranges when it encounters assertions of the form var != cnstLimit by checking if the current range boundaries match the limit value and adjusting them accordingly.

  • Replaces simple skip behavior for != assertions with range tightening logic
  • When var != 100 and range is [100, X], tightens to [101, X]
  • When var != 100 and range is [Y, 100], tightens to [Y, 99]

@EgorBo
Copy link
Member Author

EgorBo commented Nov 3, 2025

PTAL @dotnet/jit-contrib a small change to improve bounds checks

@EgorBo EgorBo requested a review from a team November 3, 2025 13:49
@EgorBo
Copy link
Member Author

EgorBo commented Nov 3, 2025

/ba-g deadletter. (And runtime-coreclr hardware-intrinsics being worked on - #121145 (comment))

@EgorBo EgorBo merged commit ebbfec3 into dotnet:main Nov 3, 2025
111 of 122 checks passed
@EgorBo EgorBo deleted the handle-gt-ne-range branch November 3, 2025 17:07
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.

Redundant bounds check

2 participants