Skip to content

Improve range analysis for checked bounds in GlobalAP#125056

Open
EgorBo wants to merge 4 commits intodotnet:mainfrom
EgorBo:improve-range-analysis
Open

Improve range analysis for checked bounds in GlobalAP#125056
EgorBo wants to merge 4 commits intodotnet:mainfrom
EgorBo:improve-range-analysis

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Mar 2, 2026

This seems to find a few diffs.

if ((uint)i < span.Length)
{
    // i is [0..int.MaxValue-1] here
}

Copilot AI review requested due to automatic review settings March 2, 2026 14:28
@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 Mar 2, 2026
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves CoreCLR JIT range analysis for unsigned comparisons against “checked bound” VNs (notably for Global Assertion Prop), allowing more precise constant-range tightening even when checked-bound symbolic limits can’t be used.

Changes:

  • Extend RangeCheck::MergeEdgeAssertions with a maxDepth parameter to bound recursive refinement.
  • Add logic (when canUseCheckedBounds == false) to infer non-negative constant ranges from O2K_CHECKED_BOUND_ADD_CNS unsigned assertions (e.g., deriving [0..INT32_MAX-1] style ranges).
  • Recursively attempt to tighten the checked-bound VN’s own constant range (within a depth limit) before applying it.

Reviewed changes

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

File Description
src/coreclr/jit/rangecheck.h Extends MergeEdgeAssertions signature with a recursion depth parameter.
src/coreclr/jit/rangecheck.cpp Implements depth-limited recursive refinement and new unsigned checked-bound range tightening path for GlobalAP scenarios.

@EgorBo EgorBo force-pushed the improve-range-analysis branch from 7896b89 to 1eb00ef Compare March 2, 2026 23:33
@EgorBo EgorBo marked this pull request as ready for review March 3, 2026 00:44
Copilot AI review requested due to automatic review settings March 3, 2026 00:44
Copy link
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 1 comment.

Copilot AI review requested due to automatic review settings March 3, 2026 14:00
Copy link
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 1 comment.

@EgorBo
Copy link
Member Author

EgorBo commented Mar 3, 2026

PTAL @jakobbotsch @dotnet/jit-contrib a couple of improvements for range analysis

@EgorBo EgorBo requested a review from jakobbotsch March 3, 2026 16:47
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