Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Jan 23, 2026

Some interesting diffs are produced.

I slowly mimic what SSA-based GetRange does, but purely on top of VNs and assertions. This should be, in theory, more powerful, doesn't require a separate "does overflow" path, can be called from Global Assertion Prop general optimizations.

simple example:

void Test(bool cond, int[] arr)
{
    int x = cond ? -1 : -2;   // [-2..-1]
    int y = arr?.Length ?? 0; // [0..Array.MaxLength]

    if (x > y) // always false -- it's now folded
        Console.WriteLine("below zero");
}

@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 Jan 23, 2026
@dotnet-policy-service
Copy link
Contributor

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

@BoyBaykiller
Copy link

With this PR is i recognized as non negative?

for (int i = 0; i < arr.Length; i++)
{
   Console.WriteLine(i >= 0); // fold to true?
}

@EgorBo
Copy link
Member Author

EgorBo commented Jan 24, 2026

With this PR is i recognized as non negative?

for (int i = 0; i < arr.Length; i++)
{
   Console.WriteLine(i >= 0); // fold to true?
}

Unfortunately, still no. We can't encode PHI in VN for this case, so i basically has no VN inside the loop body in this case. SSA+Assertions and/or IV is the only way for loops.

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