Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Feb 1, 2026

Removed a bunch of TP-heavy logic with minimal value (e.g. benchmarks.run regressed by +35 bytes, overall regression is +2700). Enabled more assertions to eat the saved TP budget (saved around -0.3% of TP).

diffs - I think +0.1..+0.2% TP regression worth the diffs

Note: with optMaxAssertionCount being unconditionally 1024 we get -600kb diffs, so if we make GAP more TP efficient we can get another -300kb

PS: I might add my own HashSet<VN> to perform O(1) lookups for "do we have an assertion for this VN" separately. While optGetVnMappedAssertions sort of did that - it wasn't used and it tried to return ASSERT_TP for VN which made it slower and still can't be used everywhere -- it was not context-dependent. For that, I need #123845 to land first (so e.g. I can make sure nobody mutates assertions in an unexpected way due to const AssertionDsc& everywhere).

Copilot AI review requested due to automatic review settings February 1, 2026 13:34
@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 1, 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.

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 pull request optimizes the Global Assertion Propagation (GlobalAP) phase of the JIT compiler by removing throughput-heavy (TP-heavy) logic that provided minimal value. The changes trade a small code size regression (+35 bytes on benchmarks.run, +2700 overall) for improved compilation throughput, with the saved budget enabling additional assertions to catch issues earlier.

Changes:

  • Simplified assertion count calculation from IL-size-based to basic block count-based heuristic
  • Removed value-number-to-assertions mapping infrastructure (optValueNumToAsserts, optAddVnAssertionMapping, optGetVnMappedAssertions)
  • Removed implied assertion generation logic (optImpliedAssertions, optImpliedByTypeOfAssertions, optImpliedByConstAssertion)
  • Removed redundant NaN filtering in optAssertionVnInvolvesNan (NaN check already exists at assertion creation)
  • Added defensive NaN assertion in optDebugCheckAssertion for O2K_CONST_DOUBLE

Reviewed changes

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

File Description
src/coreclr/jit/rangecheck.cpp Removed obsolete comment referencing the removed optImpliedAssertions function
src/coreclr/jit/compiler.h Removed declarations for ValueNumToAssertsMap infrastructure and implied assertion functions, with formatting cleanup
src/coreclr/jit/assertionprop.cpp Simplified optAssertionInit with new assertion count heuristic; removed VN-to-assertions mapping code, NaN pre-filtering, and all implied assertion generation logic; added NaN assertion check in optDebugCheckAssertion; removed calls to removed functions throughout

//
static const AssertionIndex countFunc[] = {64, 128, 256, 128, 64};
static const unsigned upperBound = ArrLen(countFunc) - 1;
const unsigned codeSize = info.compILCodeSize / 512;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compILCodeSize is not a reliable metric - we don't even sum it with inlinees. fgBBcount is a bit more reliable. Blocks might be huge, but I didn't want to complicate the complexity check. Long term I think we should unconditionally enable it for all sizes to be 256 once we improve a couple of slow things.


// Even though the propagation step takes care of NaN, just a check
// to make sure there is no slot involving a NaN.
if (optAssertionVnInvolvesNan(newAssertion))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never produce constant assertions with NaN values anyway, moved to optDebugCheckAssertion

@EgorBo EgorBo marked this pull request as ready for review February 1, 2026 15:04
@EgorBo EgorBo requested a review from AndyAyersMS February 1, 2026 15:04
@EgorBo
Copy link
Member Author

EgorBo commented Feb 1, 2026

@AndyAyersMS @dotnet/jit-contrib PTAL (see main descr)

@hez2010
Copy link
Contributor

hez2010 commented Feb 1, 2026

I'm wondering with this change can we finally enable #101763 again?

@EgorBo
Copy link
Member Author

EgorBo commented Feb 1, 2026

I'm wondering with this change can we finally enable #101763 again?

Not sure, I changed the Global Assertion Prop while that PR used Local Assertion Prop

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