-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Removed JIT (uint) cast workaround to elide bound-checks in CoreLib #67448
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cf4ccd4
Removed (uint) cast workaround in CoreLib, annotated missing places w…
gfoidl af9b2d6
Fixed the bug I introduced in TimeSpanParse.TimeSpanTokenizer
gfoidl 19b8e00
Use uint-cast on both sided for clarity
gfoidl 33cd7a1
Added missing namespace (oops)
gfoidl 20842e6
Use uint-division in BitHelper as the JIT can produce more efficient …
gfoidl da31c0b
Don't have struct local in ValueStringBuilder due to hitting JIT opti…
gfoidl 7e816a5
BitHelper with uint division and without Math.DivRem for even better …
gfoidl d9f4e01
BitHelper needs local Span due to regression in jit-diff otherwise
gfoidl 034dd89
Fixed dumb copy & paste failure in BitHelper.IsMarked
gfoidl 76d6d2a
Merge branch 'main' into remove-bound-check-hack
gfoidl 186fb58
Added Debug.Asserts to BitHelper's method that take bitPosition
gfoidl 6afa6c2
BitHelper: comment for workaround to tracking issue
gfoidl 26f459f
Update src/libraries/System.Private.CoreLib/src/System/Collections/Ge…
gfoidl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BitHelper: comment for workaround to tracking issue
- Loading branch information
commit 6afa6c2654cced379d920d97a9e3578f87d3fb6f
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ internal void MarkBit(int bitPosition) | |
| Debug.Assert(bitPosition >= 0); | ||
|
|
||
| uint bitArrayIndex = (uint)bitPosition / IntSize; | ||
|
|
||
| // Workaround for https://github.com/dotnet/runtime/issues/72004 | ||
| Span<int> span = _span; | ||
| if (bitArrayIndex < (uint)span.Length) | ||
| { | ||
|
|
@@ -36,6 +38,8 @@ internal bool IsMarked(int bitPosition) | |
| Debug.Assert(bitPosition >= 0); | ||
|
|
||
| uint bitArrayIndex = (uint)bitPosition / IntSize; | ||
|
|
||
| // Workaround for https://github.com/dotnet/runtime/issues/72004 | ||
| Span<int> span = _span; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one can use a tracking issue. The JIT should be smart enough to make it unnecessary to cache the Span here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Filed #72004 for this. |
||
| return | ||
| bitArrayIndex < (uint)span.Length && | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Same for this one, its doing the same thing but via "more code" now. I'd also expect the JIT was already hoisting the span since its a field of a struct.
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.
It is not the same thing. Unsigned division is a simple shift. Signed division is more complicated.
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.
Unfortunately that's not the case*. Codegen was validated for this change.
* (at least when the PR was created, at the moment I don't have enough time to check again)
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.
The operation is "the same" even if the codegen is different. If we're doing this specifically to take advantage of the codegen, there should be a comment on it.
More generally, we also need some assert that the input is definitely positive -or- should be taking the input as
uintand expecting the caller handle the validation/assertions. The current usages all look to be but its also always the output ofGetIndexso without the corresponding outer checks, it'd be pretty easy for someone to accidentally pass in-1here from some refactoring.If we're going to be making the method less readable, we should include a comment explaining why these tricks are being used (just as all the current cases have a small
// uint cast, per https://github.com/dotnet/runtime/issues/10596or similar comment). Ideally the issue tracks ways to improve the JIT handling where we can't improve it ourselves via signature changes, locals, or other tweaks.