-
Notifications
You must be signed in to change notification settings - Fork 5.1k
RangeCheck: Don't create invalid ranges #113935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
/azp list |
This comment was marked as resolved.
This comment was marked as resolved.
/azp run runtime-coreclr outerloop, runtime-coreclr jitstress, runtime-coreclr pgo, runtime-coreclr libraries-pgo, runtime-coreclr pgostress |
Azure Pipelines successfully started running 5 pipeline(s). |
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
@dotnet/jit-contrib @amanasifkhalid PTAL In theory, invalid ranges are fine to have e.g.:
and we still may extract useful info from that, but looks like many existing Range operations do not expect them so it's safer to just give up on them. They used to be not a problem when we used Range only for bounds checks, but we now use it for actual transformations in AssertProp as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Were we expecting regressions? e.g. linux arm64 seeing +1.22% in runtime/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs Line 258 in 7ed5ede
|
Are we currently dead code eliminating these cases? |
@EgorBo have you had a chance to look at the insertion sort regression? |
Sorry for the delayed response.
RangeCheck uses a powerful and slow "Assertions + SSA-based analysis" mechanism and we don't use the same thing to fold unreachable branches. We re-use a limited form of it in the Global Assertion prop, but we don't use SSA-based analysis there because it's too slow (adds >1% TP regression), we only use assertions.
I've looked at those and while they look unfortunate (just a few functions), JIT had no right to optimize them based on what it analyzed: https://www.diffchecker.com/53WlCbZL/
runtime/src/libraries/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs Lines 1039 to 1057 in 0eb2b0a
This is just too complex flow for current jit's BCE to properly analyze it. Given that this PR unlocks @amanasifkhalid PR and fixes access violation in #116571 I think we should just accept it. I might still allow these functions to report "invalid" ranges like this, but at the moment I think various RangeOps:: simply don't expect them and produce invalid results. Also, for e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. CI is in pretty rough shape, so we might want to wait for the next run before merging. Thanks!
Fixes a bug @amanasifkhalid hit in #113709
It is possible to create ranges where their lower limit is greater than the upper in
MergeEdgeAssertions
. E.g.Some of our range operations (
RangeOps::Merge
specifically) do invalid operations on such ranges, so instead of fixing such places, I propose we don't create them in the first place (give up on them).Normally, this should not cause issues as such array accesses likely will never be accessible anyway, but we now use range analysis in assertprop