Track span.Length's negativity + remove unsound assumption from MergeEdgeAssertions#124387
Merged
EgorBo merged 4 commits intodotnet:mainfrom Feb 16, 2026
Merged
Track span.Length's negativity + remove unsound assumption from MergeEdgeAssertions#124387EgorBo merged 4 commits intodotnet:mainfrom
EgorBo merged 4 commits intodotnet:mainfrom
Conversation
…EdgeAssertions + support VNF_Not in GetRangeFromAssertions
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request enhances range check analysis in the JIT compiler by:
- Adding support for tracking span.Length's non-negativity through assertions
- Adding support for VNF_NOT (logical not) operations in range analysis
- Removing unsound assumptions from MergeEdgeAssertions that incorrectly used checked bounds
- Adding debug-only assertions to AssertionDsc to catch mode confusion between local and global assertion propagation
Changes:
- Added RangeOps::Not() for logical negation on constant boolean ranges
- Added VNF_NOT case to GetRangeFromAssertions with proper range computation
- Removed unsafe code in MergeEdgeAssertions that made unsound assumptions about checked bounds
- Added debug-only m_compiler fields to AssertionDscOp1/Op2 with mode-checking assertions in getters
- Removed unused O2K_INVALID enum value
- Added CreateEmptyAssertion factory to ensure proper initialization of debug fields
- Added GT_LCL_VAR case in optAssertionGen to generate assertions for never-negative locals
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/jit/rangecheck.h | Added RangeOps::Not() method for logical negation on boolean ranges |
| src/coreclr/jit/rangecheck.cpp | Added VNF_NOT support in GetRangeFromAssertions; removed unsound assumptions in MergeEdgeAssertions |
| src/coreclr/jit/compiler.h | Added debug assertions to AssertionDsc with CreateEmptyAssertion factory; removed O2K_INVALID |
| src/coreclr/jit/assertionprop.cpp | Added GT_LCL_VAR case for never-negative locals; updated factory method calls to pass compiler |
Member
Author
|
PTAL @jakobbotsch I remember you pointed me to that assumption. cc @dotnet/jit-contrib |
Member
Author
|
Managed to come up with a bug-repro that this PR fixes: #124404 |
This was referenced Feb 13, 2026
Open
jakobbotsch
reviewed
Feb 16, 2026
jakobbotsch
reviewed
Feb 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/coreclr/jit/rangecheck.cpp:712
- RangeOps::Not() method does not exist. This code calls RangeOps::Not(r1) but the RangeOps struct in rangecheck.h only defines methods like Negate, Add, Subtract, Multiply, etc. There is no Not method implemented. This will cause a compilation error. You need to either implement RangeOps::Not() or remove the VNF_NOT case from this switch statement.
jakobbotsch
approved these changes
Feb 16, 2026
Member
Author
|
/ba-g filed #124487 for the failure |
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.
This PR does:
IsVnCheckedBoundjust consults with a global VN hash of VNs ever participating in BoundsCheck's length arg. While in reality we can only rely on such VNs in certain contexts, e.g. after BoundsCheck nodes. Fixes AVE instead of IndexOutOfRangeException #124404Diffs - some regressions from the removed IsVnCheckedBound hack and now non-promoted Spans are less likely to be recognized. Likely to be fixed when the legacy promotion is gone?