Fold Span.Slice(X) like bound checks#122040
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR optimizes bound checks for Span.Slice(X) operations by eliminating redundant checks when sufficient range information is available from assertions. The optimization reduces code size by approximately 41% in the example case (from 68 to 40 bytes).
- Adds support for subtracting constant limits in range operations
- Refactors range operations to use a generic template-based approach
- Implements peeling of constant offsets from ADD operations in relational comparisons
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/coreclr/jit/rangecheck.h | Introduces SubtractConstantLimit function and refactors Add, Subtract, and Multiply operations to use a generic ApplyRangeOp template, eliminating code duplication |
| src/coreclr/jit/assertionprop.cpp | Adds logic to peel constant offsets from ADD operations in relational comparisons, enabling range-based optimization for expressions like X + CNS relop Y |
|
PTAL @dotnet/jit-contrib some nice diffs. Another way to handle |
Diffs.
Was:
Now: