Skip to content

Improve RangeOps::Merge#129390

Open
EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:improve-rangeops-merge
Open

Improve RangeOps::Merge#129390
EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:improve-rangeops-merge

Conversation

@EgorBo

@EgorBo EgorBo commented Jun 14, 2026

Copy link
Copy Markdown
Member

Fold more bound checks with up to -110k diffs

RangeOps::Merge is typically used when we merge ranges from PHI args, e,g, [0..1] U [10..10] becomes [0..10]

Note

This PR was authored with assistance from GitHub Copilot CLI (AI). The change was validated locally via SuperPMI asmdiffs.

Copilot AI review requested due to automatic review settings June 14, 2026 15:53
@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 14, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

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 tweaks RangeOps::Merge in the CoreCLR JIT range analysis to broaden when certain symbolic/constant merge rules apply, aiming to improve SPMI code size by producing tighter (or more frequently-applicable) merged ranges.

Changes:

  • Relaxes the “widen upper limit” heuristic when merging a constant upper bound with a $bnd + cns upper bound.
  • Generalizes the “binop-array lower bound + constant lower bound” merge rule by removing the prior cns <= 0 gating and updating the accompanying rationale comment.

Comment thread src/coreclr/jit/rangecheck.h Outdated
Drop the redundant `k >= 0` guard on the upper-limit widening rule
Max(k, ($bnd + n)) => ($bnd + n): since $bnd >= 0 and n >= k, the result
($bnd + n) is already >= k for any sign of k, and it stays symbolic so a
possible overflow is preserved.

The lower-limit rule keeps its cns <= 0 guard: for cns > 0, ($bnd + cns) can
overflow (e.g. a Span length is bounded by INT_MAX), so collapsing it to a
constant would be an unsound (too-high) lower bound.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@EgorBo EgorBo force-pushed the improve-rangeops-merge branch from a147003 to afa9a93 Compare June 14, 2026 17:23
@EgorBo EgorBo closed this Jun 14, 2026
@EgorBo EgorBo reopened this Jun 14, 2026
@EgorBo

EgorBo commented Jun 15, 2026

Copy link
Copy Markdown
Member Author

PTAL @AndyAyersMS @dotnet/jit-contrib

@EgorBo EgorBo requested a review from AndyAyersMS June 15, 2026 17:32
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.

3 participants