Skip to content

Misc improvements for rangecheck#129101

Merged
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:rangecheck-misc-improvements
Jun 8, 2026
Merged

Misc improvements for rangecheck#129101
EgorBo merged 1 commit into
dotnet:mainfrom
EgorBo:rangecheck-misc-improvements

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented Jun 7, 2026

  • Fix unsound bounds in RangeOps::Or (could exclude reachable values); use max-based lower/upper bounds
    • existing bug: [3..5] | [4..7] -> lo = 3|4 = 7, hi = 5|7 = 7 (claims [7..7])
  • Add UDIV constant-range support to GetRangeFromAssertionsWorker
  • Populate m_isVNNeverNegative on checked-bound / VN-relop assertions
  • Restrict the never-negative O2K_VN_ADD_CNS range deduction to LT/LE relops (GT/GE were unsound)

Diffs

- Fix unsound bounds in RangeOps::Or (could exclude reachable values); use max-based lower/upper bounds
- Add UDIV constant-range support to GetRangeFromAssertionsWorker
- Populate m_isVNNeverNegative on checked-bound / VN-relop assertions (and fix the operand used)
- Restrict the never-negative O2K_VN_ADD_CNS range deduction to LT/LE relops (GT/GE were unsound)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 7, 2026 21:15
@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 7, 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.

Copy link
Copy Markdown
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

This PR refines CoreCLR JIT range analysis and assertion metadata to both fix identified unsound deductions and modestly extend the set of VN operations that can be range-evaluated from assertions.

Changes:

  • Fix RangeOps::Or to produce sound bounds for bitwise OR over non-negative constant ranges by using max-based lower bounds and a conservative “fill lower bits” upper bound.
  • Extend RangeCheck::GetRangeFromAssertionsWorker to compute constant ranges for VNF_UDIV (unsigned division) when both operands have suitable constant ranges.
  • Improve assertion metadata by propagating m_isVNNeverNegative for O2K_VN_ADD_CNS in checked-bound and VN-relop assertions, and restrict a previously-unsound range deduction fast path to LT/LE-style relops.

Reviewed changes

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

File Description
src/coreclr/jit/rangecheck.h Adjusts OR range computation to avoid excluding reachable values; adds constant-range support for unsigned division.
src/coreclr/jit/rangecheck.cpp Enables VNF_UDIV range evaluation from assertions; restricts a never-negative O2K_VN_ADD_CNS fast path to sound relops.
src/coreclr/jit/compiler.h Populates O2K_VN_ADD_CNS::m_isVNNeverNegative based on VN analysis for checked-bound and VN-relop assertions.

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Jun 8, 2026

PTAL @jakobbotsch @dotnet/jit-contrib a couple of improvements + 2 correctness fixes, diffs

@EgorBo EgorBo requested a review from jakobbotsch June 8, 2026 11:22
@EgorBo EgorBo merged commit a075769 into dotnet:main Jun 8, 2026
146 of 148 checks passed
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.

4 participants