Remove bounds checks for 'i + cns < len' pattern#124242
Merged
EgorBo merged 9 commits intodotnet:mainfrom Feb 11, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates CoreCLR JIT range-check analysis to recognize unsigned compare patterns like (uint)(i + cns) < (uint)len and use them to tighten inferred ranges, enabling elimination of redundant bounds checks for nearby indices (e.g., i+1, i+2) in common Span/array loops.
Changes:
- Extend
RangeCheck::MergeEdgeAssertionsto derive a range for a base value number (normalLclVN) from an assertion on an offset form (normalLclVN + cns). - Prefer deductions that relate the base induction variable to the “preferred” checked bound VN (typically the length VN).
EgorBo
commented
Feb 11, 2026
Member
Author
|
PTAL @jakobbotsch @dotnet/jit-contrib |
jakobbotsch
approved these changes
Feb 11, 2026
Member
Author
|
/ba-g deadletter + infra issues + filed #124279 |
gniumg-source
added a commit
to gniumg-source/runtime
that referenced
this pull request
Feb 11, 2026
Closed
This was referenced Feb 11, 2026
Open
EgorBo
added a commit
that referenced
this pull request
Feb 12, 2026
Bad merge of two PRs at once. #124132 - introduced a VN cache to find out if we have any assertions for a VN. And #124242 introduced a VN decomposition inside MergeEdgeAssertion loop where it tries to match VNF_ADD(X, CNS). So the fix is to register VNF_ADD's op1 VN as well. As the result, #124242 couldn't find the matching assertion and the FILECHECK test failed due to bounds check in the codegen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #121262
New codegen:
Diffs