Skip to content

JIT: fold trivial redundant comparisons on loop induction variables#130205

Open
EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:jit-rangecheck-budget
Open

JIT: fold trivial redundant comparisons on loop induction variables#130205
EgorBo wants to merge 2 commits into
dotnet:mainfrom
EgorBo:jit-rangecheck-budget

Conversation

@EgorBo

@EgorBo EgorBo commented Jul 4, 2026

Copy link
Copy Markdown
Member

Closes #130206

static void Test()
{
    for (int i = 0; i < 100; i++)
    {
        if (i >= 0) // never false
        {
            Console.WriteLine("Hi");
        }
    }
}
 G_M24707_IG02:
        xor      ebx, ebx
        mov      rsi, 0x...      ; 'Hi'
-       jmp      SHORT G_M24707_IG05
-G_M24707_IG03:
-       inc      ebx
-G_M24707_IG04:
-       test     ebx, ebx
-       jl       SHORT G_M24707_IG03
-G_M24707_IG05:
+G_M24707_IG03:
        mov      rcx, rsi
        call     [System.Console:WriteLine(System.String)]
        inc      ebx
        cmp      ebx, 100
-       jl       SHORT G_M24707_IG04
+       jl       SHORT G_M24707_IG03

Some nice diffs, mostly in tests, though.

Copilot AI review requested due to automatic review settings July 4, 2026 20:09
@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 Jul 4, 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 adjusts assertion propagation’s SSA-based range query budget so that RangeCheck::TryGetRange can successfully compute ranges for common loop induction-variable patterns, enabling folding of trivially redundant comparisons.

Changes:

  • Increase the default SSA walk budget used by assertionprop’s slow GetRange path from 64 to 256.
  • Add an explanatory comment describing why TryGetRange needs a larger shared budget due to multiple internal SSA walks.

Comment thread src/coreclr/jit/assertionprop.cpp
@EgorBo

EgorBo commented Jul 4, 2026

Copy link
Copy Markdown
Member Author

@MihuBot -nuget

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 wasn't able to review any files in this pull request.

@EgorBo EgorBo reopened this Jul 5, 2026
Copilot AI review requested due to automatic review settings July 5, 2026 14:45

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

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

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

JIT: SSA-based TryGetRange fails on constant

3 participants