JIT: restore type-based upper bound for RSZ in range analysis#128146
Open
EgorBo wants to merge 2 commits into
Open
JIT: restore type-based upper bound for RSZ in range analysis#128146EgorBo wants to merge 2 commits into
EgorBo wants to merge 2 commits into
Conversation
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts CoreCLR JIT range analysis for logical right shifts (GT_RSZ) to recover tighter, type-based upper bounds so bounds-check elimination opportunities aren’t lost when the shift count is known but the shifted value’s range isn’t a helpful constant.
Changes:
- Extends
RangeOps::ShiftRightto accept anop1BitWidthand uses it (for logical shifts) to compute a type-based upper boundUMAX(op1Type) >> minShiftand to force a non-negative lower bound when shifting by at least 1. - Passes the shift operand’s bit width from
RangeCheck::ComputeRangeForBinOpwhen analyzingGT_RSZ. - Adds JIT tests asserting bounds checks are elided for
i >>> 31indexing into a 2-element span andi >>> 28indexing into a 16-element span.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/tests/JIT/opt/RangeChecks/ElidedBoundsChecks.cs | Adds regression coverage for bounds-check elimination on logical right shift–derived indices. |
| src/coreclr/jit/rangecheck.h | Enhances RangeOps::ShiftRight with an optional operand bit-width parameter and type-based bound derivation for logical shifts. |
| src/coreclr/jit/rangecheck.cpp | Supplies operand bit width to ShiftRight for GT_RSZ range computation. |
791b33d to
81ffe2a
Compare
PR dotnet#122263 dropped the type-based RSZ fallback that derives an upper bound from op1's bit-width when r1's range isn't a useful constant. As a result, patterns like `vals[i >>> 31]` against a length-2 span no longer had their bounds check eliminated. For RSZ by N >= 1 with r1 not proven non-negative, override with the sound [0, UINT_MAX >> N] bound. (RSZ here is always 32-bit since GetRangeWorker bails out on TYP_LONG and CIL shifts have no small-typed operands.) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jakobbotsch
approved these changes
May 13, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
fix a regression in range check elimination found by @saucecontrol for: