Skip to content

JIT: handle relational operators in range overflow analysis - #134375

Merged
EgorBo merged 2 commits into
mainfrom
copilot/fix-redundant-bound-check
Sep 24, 2026
Merged

EgorBo merged 2 commits into
mainfrom
copilot/fix-redundant-bound-check

Conversation

Copilot AI commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

GetClosestCosineIndex retains two redundant bounds checks because overflow analysis rejects relational expressions.

  • Change: Treat comparisons as non-overflowing while retaining recursive overflow checks on both operands.
  • Codegen: Removes both checks on Linux x64; code shrinks from 247 to 225 bytes and 77 to 71 instructions.

@azure-pipelines

azure-pipelines Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI linked an issue Sep 21, 2026 that may be closed by this pull request
@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 Sep 21, 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 changed the title [WIP] Fix redundant bound check in GetClosestCosineIndex JIT: handle relational operators in range overflow analysis Sep 21, 2026
Copilot AI requested a review from EgorBo September 21, 2026 21:25
@EgorBo
EgorBo marked this pull request as ready for review September 21, 2026 23:22
Copilot AI lite review requested due to automatic review settings September 21, 2026 23:22

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.

Copilot review overview

🟡 Changes recommended

Add a focused regression test covering the relational-expression optimization path.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Updates JIT range-overflow analysis to recognize relational operators and eliminate redundant bounds checks.

Changes:

  • Treats comparisons as non-overflowing while checking operands recursively.
  • Enables bounds-check elimination for comparison-based expressions.
File Description
src/​coreclr/​jit/​rangecheck.cpp Extends overflow analysis to relational operators.

Comment thread src/coreclr/jit/rangecheck.cpp Resolved
@EgorBo

EgorBo commented Sep 22, 2026

Copy link
Copy Markdown
Member

PTAL @AndyAyersMS very few diffs, but the change is one-liner. I was looking at user code that contained a redundant bound check (see #134368). Turns out JIT was conservatively giving up in DoesOverflow for index being a relop. Relop is always just 0 or 1, but I also conservatively check operands for overflow.

@EgorBo
EgorBo requested a review from AndyAyersMS September 22, 2026 00:37
@EgorBo
EgorBo enabled auto-merge (squash) September 24, 2026 10:51
@EgorBo
EgorBo merged commit 117f900 into main Sep 24, 2026
135 of 136 checks passed
@EgorBo
EgorBo deleted the copilot/fix-redundant-bound-check branch September 24, 2026 10:52
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 25, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

JIT: (CQ) redundant bound check

5 participants