Skip to content

Clean up in rangecheck#129144

Open
EgorBo wants to merge 3 commits into
dotnet:mainfrom
EgorBo:cleanup-rangecheck
Open

Clean up in rangecheck#129144
EgorBo wants to merge 3 commits into
dotnet:mainfrom
EgorBo:cleanup-rangecheck

Conversation

@EgorBo

@EgorBo EgorBo commented Jun 8, 2026

Copy link
Copy Markdown
Member

Minor cleanup in rangecheck.cpp:

  • Range Check was trying to do what assertionprop already did - handle constant indices. Removed with zero diffs.
  • The previous code had a correctness issue - it called a slow SSA-based GetRangeWorker for Array's length but didn't use DoesOverflow that must be called for GetRangeWorker. Instead, I just call the VN-based GetRangeFromAssertions (that plays nicely with overflows) and it seems to be enough, a few minor regression, a minor TP improvement.

Note

This PR was generated with the assistance of GitHub Copilot.

Diffs (from an incorrect call to GetRangeWorker without DoesOverflow)

Remove the now-redundant optIsTreeKnownIntValue helper and the ad-hoc constant-index/arrSize handling in OptimizeRangeCheck. The array size is now derived consistently through GetRangeFromAssertions, which also recovers the exact size for new T[cns].Length via TryGetNewArrSize.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 8, 2026 23:23
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 8, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors CoreCLR JIT bounds-check range analysis in rangecheck.cpp by removing a now-redundant constant-index fast path and a helper (optIsTreeKnownIntValue) in favor of using conservative VNs plus the existing assertion-based range machinery.

Changes:

  • Simplifies RangeCheck::OptimizeRangeCheck by dropping the dedicated constant-index / arrSize computation path and relying on TryGetRange + BetweenBounds.
  • Extends assertion-based range recovery for VNF_ARR_LENGTH to tighten to an exact length for new T[cns].Length via TryGetNewArrSize.
  • Removes Compiler::optIsTreeKnownIntValue declaration and definition.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/rangecheck.cpp Refactors bounds-check removal to rely on VN + assertion-based range info; enhances VNF_ARR_LENGTH assertion-range inference.
src/coreclr/jit/compiler.h Removes the optIsTreeKnownIntValue declaration.
src/coreclr/jit/assertionprop.cpp Removes the optIsTreeKnownIntValue implementation.
Comments suppressed due to low confidence (1)

src/coreclr/jit/rangecheck.cpp:806

  • GetRangeFromAssertionsWorker returns early for GC VN types (varTypeIsGC(vnType)), so VNF_StrFastAllocate (which represents a string ref VN) is effectively unreachable here. Leaving it in the int-range switch adds dead code and can mislead readers into thinking StrFastAllocate is an int-producing VN.
            case VNF_GT:
            case VNF_GT_UN:
            case VNF_GE:
            case VNF_GE_UN:
            case VNF_LT:
            case VNF_LT_UN:

Copilot AI review requested due to automatic review settings June 8, 2026 23:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/coreclr/jit/rangecheck.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants