-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Optimize more bound checks around logical operators #122263
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
base: main
Are you sure you want to change the base?
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
| int i; | ||
|
|
||
| // get a pointer to the base64 table to avoid unnecessary range checking | ||
| fixed (byte* base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="u8) |
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.
Can we remove unsafe from ConvertToBase64Array's two callers?
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.
@am11 do you mean bounds checks over outChars? last I checked that still emits checks, I'll take a look separately
|
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
90ae7aa to
d2e3c3c
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
|
/azp run Fuzzlyn |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Pull request overview
This PR optimizes bounds check elimination for expressions involving bitwise AND, OR, and shift operations. The JIT compiler's range check analysis is enhanced to understand value ranges produced by these operations, enabling automatic elimination of bounds checks in patterns like base64 encoding where bitwise operations produce values that are provably within array bounds.
Changes:
- Enhanced JIT range check analysis to compute ranges for GT_AND, GT_OR, and GT_UMOD operations
- Refactored
ComputeRangeForBinOpto use a cleaner switch-based dispatch and lambda for range computation - Modified System.Private.CoreLib's Convert.ConvertToBase64Array to use ReadOnlySpan instead of fixed pointers, relying on the enhanced range check elimination
- Added natvis debugging visualizations for Limit and Range types
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Convert.cs | Changed ConvertToBase64Array from using fixed pointer to ReadOnlySpan, removing one level of indentation; logic otherwise unchanged |
| src/coreclr/jit/rangecheck.h | Added new range operations: ShiftLeft, And, Or, and UnsignedMod to compute value ranges for these binary operations |
| src/coreclr/jit/rangecheck.cpp | Refactored ComputeRangeForBinOp to use switch statement dispatch and added support for GT_OR; removed GT_RSZ from range computation |
| src/coreclr/jit/clrjit.natvis | Added debugging visualizers for Limit and Range types |
1e09cca to
b082f0e
Compare
Closes #122150
Example:
Was:
Now:
As the result, was able to optimize bound checks in Convert.ConvertToBase64Array