Skip to content

Revert "Revert 'Increase number of assertions (GlobalAP) + VN cache (#124132)'"#125215

Merged
EgorBo merged 2 commits intomainfrom
copilot/revert-changes-from-124928
Mar 5, 2026
Merged

Revert "Revert 'Increase number of assertions (GlobalAP) + VN cache (#124132)'"#125215
EgorBo merged 2 commits intomainfrom
copilot/revert-changes-from-124928

Conversation

Copy link
Contributor

Copilot AI commented Mar 5, 2026

Diffs

Re-applies #124132 which was reverted in #124928 due to excessive JIT memory allocation. That root cause has since been fixed.

Description

assertionprop.cpp / compiler.h — VN existence cache

  • Adds optAssertionVNsMap (VNSet*): lazily-initialized map tracking which VNs have at least one assertion
  • Adds optAssertionHasAssertionsForVN(vn, addIfNotFound): O(1) lookup; when addIfNotFound=true registers the VN on first insertion
  • optAddAssertion: uses the cache to gate the full O(n) table scan for duplicates; also registers op2 bound VN and the VN + const operand VN (fix from #124306) so MergeEdgeAssertions can find them
  • optAssertionProp_LclVar: early-outs via cache before iterating assertions; pre-computes treeVN once instead of re-deriving it in the loop
  • optAssertionVNIsNonNull: skips iteration when cache says no assertions exist for the VN

assertionprop.cppoptMaxAssertionCount heuristic

  • Replaces the IL-code-size step-function table with the empirically-validated formula:
    max(64, min(256, (lvaTrackedCount + 3 * fgBBcount + 48) >> 2))
    
    Validated across 1.1M compiled methods: 94.6% stay at the 64 floor, 0.4% hit the 256 cap, worst-case underprediction of 127 for 481 methods (0.043%).

rangecheck.cpp

  • MergeEdgeAssertions: replaces normalLclVN == NoVN guard with !optAssertionHasAssertionsForVN(normalLclVN) — handles the NoVN case internally and also skips the loop when no relevant assertions were ever registered.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/runtime-infrastructure
See info in area-owners.md if you want to be subscribed.

…124132)'"

Re-applies the changes from PR #124132 that were reverted in PR #124928 due to a bug causing excessive memory allocation during jitting. The bug has since been fixed.

Changes:
- Formula-based optMaxAssertionCount heuristic (basicBlocks + tracked locals)
- VN cache (optAssertionHasAssertionsForVN) for fast O(1) lookup
- optAssertionVNsMap field added to Compiler
- optAddAssertion uses VN cache for duplicate detection/registration
- Early return in optAssertionProp_LclVar when no assertions for VN
- VN cache check in optAssertionVNIsNonNull
- rangecheck.cpp uses optAssertionHasAssertionsForVN instead of NoVN check
- Includes addOpVN pattern fix from PR #124306

Co-authored-by: EgorBo <523221+EgorBo@users.noreply.github.com>
Copilot AI changed the title [WIP] Revert changes from PR 124928 after fixing uncovered bug Revert "Revert 'Increase number of assertions (GlobalAP) + VN cache (#124132)'" Mar 5, 2026
@EgorBo EgorBo marked this pull request as ready for review March 5, 2026 14:02
Copilot AI review requested due to automatic review settings March 5, 2026 14:02
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 re-applies the changes from #124132 (which was reverted in #124928 due to excessive JIT memory allocation). It improves the JIT's assertion propagation by adding a VN (Value Number) existence cache for O(1) lookups and refining the heuristic for sizing the global assertion table.

Changes:

  • Replaces the IL-code-size step-function table for optMaxAssertionCount with an empirically-validated formula based on tracked local count and basic block count, yielding assertion table sizes between 64 and 256.
  • Adds optAssertionVNsMap (a lazily-initialized VNSet* cache) and optAssertionHasAssertionsForVN() to enable O(1) checks for whether any assertions exist for a given VN, avoiding expensive O(n) table scans in optAddAssertion, optAssertionProp_LclVar, optAssertionVNIsNonNull, and MergeEdgeAssertions.
  • Includes the fix from #124306: registers the decomposed VNF_ADD operand VN in the cache so MergeEdgeAssertions can find matching assertions for the VN + const pattern.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/compiler.h Adds VNSet* optAssertionVNsMap field and declares optAssertionHasAssertionsForVN() method.
src/coreclr/jit/assertionprop.cpp Replaces assertion table sizing heuristic; adds VN cache gating for duplicate detection in optAddAssertion, early-out in optAssertionProp_LclVar and optAssertionVNIsNonNull; implements optAssertionHasAssertionsForVN().
src/coreclr/jit/rangecheck.cpp Replaces the NoVN guard in MergeEdgeAssertions with the VN cache check, which also handles NoVN internally.

@EgorBo
Copy link
Member

EgorBo commented Mar 5, 2026

PTAL @AndyAyersMS @dotnet/jit-contrib This PR reverts the revert as the issue was fixed. Diffs

@EgorBo EgorBo requested a review from AndyAyersMS March 5, 2026 15:32
@EgorBo EgorBo merged commit 4776f44 into main Mar 5, 2026
138 checks passed
@EgorBo EgorBo deleted the copilot/revert-changes-from-124928 branch March 5, 2026 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants