Skip to content

Increase number of assertions (GlobalAP) + VN cache#124132

Merged
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:cache-vn-2
Feb 11, 2026
Merged

Increase number of assertions (GlobalAP) + VN cache#124132
EgorBo merged 2 commits intodotnet:mainfrom
EgorBo:cache-vn-2

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.

@EgorBo
Copy link
Member Author

EgorBo commented Feb 11, 2026

ping @AndyAyersMS

@EgorBo EgorBo merged commit 92741be into dotnet:main Feb 11, 2026
136 checks passed
@EgorBo EgorBo deleted the cache-vn-2 branch February 11, 2026 18:41
EgorBo added a commit that referenced this pull request Feb 12, 2026
Bad merge of two PRs at once.
#124132 - introduced a VN cache to
find out if we have any assertions for a VN. And
#124242 introduced a VN
decomposition inside MergeEdgeAssertion loop where it tries to match
VNF_ADD(X, CNS). So the fix is to register VNF_ADD's op1 VN as well.

As the result, #124242 couldn't
find the matching assertion and the FILECHECK test failed due to bounds
check in the codegen.
AndyAyersMS added a commit to AndyAyersMS/runtime that referenced this pull request Feb 26, 2026
AndyAyersMS added a commit that referenced this pull request Feb 27, 2026
#124928)

This reverts commit 92741be.

This was causing excessive memory allocation during jitting (see
dotnet/dotnet#4933).
github-actions bot pushed a commit that referenced this pull request Feb 27, 2026
akoeplinger pushed a commit that referenced this pull request Feb 27, 2026
…AP) + VN cache (#124132)" (#124955)

Backport of #124928 to release/11.0-preview2

/cc @akoeplinger @AndyAyersMS

## Customer Impact

- [ ] Customer reported
- [x] Found internally

This was causing excessive memory allocation during jitting (see
dotnet/dotnet#4933).
## Regression

- [X] Yes
- [ ] No

Caused by:
92741be

## Testing

Manual testing.

## Risk

Low. Reverts an earlier change.

[High/Medium/Low. Justify the indication by mentioning how risks were
measured and addressed.]

**IMPORTANT**: If this backport is for a servicing release, please
verify that:

- For .NET 8 and .NET 9: The PR target branch is `release/X.0-staging`,
not `release/X.0`.
- For .NET 10+: The PR target branch is `release/X.0` (no `-staging`
suffix).

## Package authoring no longer needed in .NET 9

**IMPORTANT**: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

Co-authored-by: Andy Ayers <andya@microsoft.com>
iremyux pushed a commit to iremyux/dotnet-runtime that referenced this pull request Mar 2, 2026
[Diffs](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1284439&view=ms.vss-build-web.run-extensions-tab)

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.

<img width="914" height="351"
alt="{3217F8D3-BE47-4C82-AA12-0281D51D519C}"
src="https://github.com/user-attachments/assets/e76eb379-bfda-4792-9c5b-d918b29a6a62"
/>

_* 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%).

<img width="1161" height="587" alt="image"
src="https://github.com/user-attachments/assets/46cd5c6d-c2ac-4341-9d0f-0cf7a92c8164"
/>
Overall, TP-wise, the most expensive thing is the forward flow analysis

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
iremyux pushed a commit to iremyux/dotnet-runtime that referenced this pull request Mar 2, 2026
Bad merge of two PRs at once.
dotnet#124132 - introduced a VN cache to
find out if we have any assertions for a VN. And
dotnet#124242 introduced a VN
decomposition inside MergeEdgeAssertion loop where it tries to match
VNF_ADD(X, CNS). So the fix is to register VNF_ADD's op1 VN as well.

As the result, dotnet#124242 couldn't
find the matching assertion and the FILECHECK test failed due to bounds
check in the codegen.
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.

3 participants