Optimize more bound checks around logical operators#122263
Optimize more bound checks around logical operators#122263EgorBo merged 6 commits intodotnet:mainfrom
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
|
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.
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
|
PTAL @dotnet/jit-contrib |
|
@AndyAyersMS I've addressed the feedback |
Closes #122150
Example:
Was:
Now:
As the result, was able to optimize bound checks in Convert.ConvertToBase64Array