Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Nov 16, 2025

Closes #121682

Removes the bounds checks in ^

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 16, 2025
@dotnet-policy-service
Copy link
Contributor

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

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 PR enhances the range check optimization by adding a fallback mechanism to determine array length using SSA-based analysis when assertion-based lookups fail. This enables removal of bounds checks in more scenarios, particularly for patterns involving index-from-end (^) operations.

Key Changes

  • Adds SSA-based range analysis as a fallback when assertion-based array length lookup fails
  • Uses the existing GetRangeWorker method to compute array length ranges when faster methods don't find a constant length

@hez2010
Copy link
Contributor

hez2010 commented Nov 16, 2025

Can you check does this also handle patterns like:

var buffer = new T[rows.Length];
var count = 0;
for (var i = 0; i < rows.Length; i++)
{
    if (predicate(rows[i])) buffer[count++] = rows[i]; // current there's bound check for buffer[count++]
}

@EgorBo
Copy link
Member Author

EgorBo commented Nov 17, 2025

Can you check does this also handle patterns like:

var buffer = new T[rows.Length];
var count = 0;
for (var i = 0; i < rows.Length; i++)
{
    if (predicate(rows[i])) buffer[count++] = rows[i]; // current there's bound check for buffer[count++]
}

it seems to be a different pattern, feel free to file an issue!

@AndyAyersMS
Copy link
Member

it seems to be a different pattern, feel free to file an issue!

Seems like that case is already covered by #116238

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.

[Bounds checks] Conditional Slice pattern

3 participants