Skip to content

Fold more branches via O1K_VN <relop> O2K_VN comparisons#127950

Draft
EgorBo wants to merge 4 commits intodotnet:mainfrom
EgorBo:o2k-vn
Draft

Fold more branches via O1K_VN <relop> O2K_VN comparisons#127950
EgorBo wants to merge 4 commits intodotnet:mainfrom
EgorBo:o2k-vn

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented May 8, 2026

Minimal example:

if (x > 10 && x < 100)
{
    if (y > x) // means y > 11
    {
        return y > 0; // always true 

Copilot AI review requested due to automatic review settings May 8, 2026 12:26
@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 May 8, 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 extends CoreCLR JIT global assertion propagation and range analysis to reason about signed comparisons where both operands are arbitrary value numbers (VN VN). The goal is to enable additional branch folding by chaining relational facts (e.g., deriving bounds for y from y > x plus existing bounds for x).

Changes:

  • Add a new global-AP assertion operand kind (O2K_VN) to represent “op2 is an arbitrary VN” for relop assertions.
  • Teach global assertion generation to create VN-to-VN relop assertions (with complementary assertions) in selected signed int32 cases.
  • Enhance RangeCheck::MergeEdgeAssertions / GetRangeFromAssertionsWorker to tighten ranges using VN-to-VN assertions via bounded recursion.

Reviewed changes

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

File Description
src/coreclr/jit/rangecheck.h Declares MergeEdgeAssertionsWorker to support bounded recursive VN-to-VN assertion resolution.
src/coreclr/jit/rangecheck.cpp Implements worker/wrapper split for edge-assertion merging and adds VN-to-VN relop-driven range tightening.
src/coreclr/jit/compiler.h Adds O2K_VN, updates assertion comparisons, and adds a factory for VN-to-VN relop assertions.
src/coreclr/jit/assertionprop.cpp Prints/debug-checks O2K_VN, registers op2 VN for lookup, and creates VN-to-VN relop assertions on JTRUE when profitable.

Comment thread src/coreclr/jit/rangecheck.cpp Outdated
Comment thread src/coreclr/jit/assertionprop.cpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 8, 2026 12:46
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

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

Comment thread src/coreclr/jit/rangecheck.cpp Outdated
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