Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Feb 7, 2026

Diffs

This PR does two things:

  1. Implements a quick O(1) check to answer: “Do we have any assertions for this VN?”
    I initially tried to use this cache everywhere, but ended up keeping it only in a few places where it had a noticeable TP benefit. This change alone has zero size diffs and reduces the TP regression from change (2) by 2×.
  2. Increases the maximum number of assertions (GlobalAP) using a heuristic.
    With help from SPMI, I analyzed 1M methods and built a large table: | BB count | TrackedLocals count | assertions created |. I then fed it to an AI agent, which iterated for a while, generated some Python scripts, and proposed a heuristic (after several rounds of SPMI TP/size feedback). This is the best trade-off between improvements and TP regression that I was able to find. We could potentially incorporate more parameters (e.g., number of conditional blocks against null/constant, number of indirects), but I think the current version is good enough for now.
{3217F8D3-BE47-4C82-AA12-0281D51D519C}

* I had 3 variants and ended up picking the 3rd one due to better TP results (obviously, less of =256 entities)

NOTE: If I unconditionally set optMaxAssertionCount to 256 the size diffs become ~8% better and TP regresses by 3x

The worst-case +0.3% TP regression should be more than covered by my earlier refactoring PRs that improved TP (the combined net effect should be around -0.5%).

image Overall, TP-wise, the most expensive thing is the forward flow analysis

Copilot AI review requested due to automatic review settings February 7, 2026 19:53
@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 Feb 7, 2026
@dotnet-policy-service
Copy link
Contributor

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

Copy link
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 increases Global Assertion Propagation capacity and adds a small VN-based cache to avoid unnecessary full-table assertion scans, benefiting range check/range analysis and assertion propagation throughput.

Changes:

  • Adjusts optMaxAssertionCount heuristics to allow tracking more assertions (especially for GlobalAP).
  • Introduces optAssertionVNsMap + optAssertionHasAssertionsForVN() to quickly determine if any assertions exist for a given VN (with lazy initialization).
  • Uses the VN cache to early-out in range-check assertion merges and GlobalAP local-var assertion propagation.

Reviewed changes

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

File Description
src/coreclr/jit/rangecheck.cpp Uses the new VN cache to skip assertion scanning when no assertions exist for the VN.
src/coreclr/jit/compiler.h Adds optAssertionVNsMap and declares optAssertionHasAssertionsForVN().
src/coreclr/jit/assertionprop.cpp Updates assertion table sizing, populates/queries the VN cache, and applies new early-out paths in GlobalAP.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 8, 2026 03:01
Copy link
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 3 out of 3 changed files in this pull request and generated no new comments.

@EgorBo
Copy link
Member Author

EgorBo commented Feb 9, 2026

@AndyAyersMS @dotnet/jit-contrib PTAL. This is still a hacky way (I mean the heuristic) to deal with the TP regression, but it's better than nothing. Very few regressions, lots of improvements, small TP regression overall.

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.

1 participant