Repository navigation
PGO: make value histograms 32-bit on all targets - #136895
Merged
Merged
Conversation
ValueHistogram was an 8-byte kind, so on 32-bit targets it was the only schema entry requiring 8-byte alignment. The VM lays out instrumentation data after a size_t-aligned schema prefix and later re-derives the layout from offset 0, so the two layouts disagreed whenever countsOffset % 8 == 4, leading to shifted reads and an over-read past the allocation (#134695). The value helpers also wrote pointer-sized entries that didn't match the schema on 32-bit. Values are only used for small integers (memmove/memcmp lengths), so record them as 32-bit ints everywhere, truncating wider values. The profiled-value expansion is guarded by a full-width runtime check, so truncation can't affect correctness. This also halves the table size on 64-bit. Bump the MIBC format version to 1.1 since old value histograms are no longer recognized, and bump the JIT-EE version. Fixes #134695 Co-authored-by: Copilot <[email protected]> Copilot-Session: fe9884cc-3de1-4d09-82cd-e2e2869df043
PgoSchemaMergeComparer matches entries by descriptor only, so a pre-1.1 ValueHistogram (0x242, 8-byte entries) and a current one (0x241, 4-byte entries) at the same IL offset collide during MIBC merges. Depending on merge order this either threw or silently kept the legacy entry, which the JIT no longer recognizes. Keep the current-format entry in either order. Co-authored-by: Copilot App <[email protected]>
Contributor
|
Tagging @dotnet/jit-contrib for JIT-EE GUID update |
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
AndyAyersMS
approved these changes
Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR uses @EgorBo's fix from #136890 (comment); his commit is cherry-picked as-is.
ValueHistogramasked for 8-byte entries and alignment it never needed. On 32-bit it was the only 8-byte-aligned kind the JIT emits. The VM lays out the schema fromcountsOffset(only 4-byte aligned) but reads it back from offset 0, so the two layouts disagreed and the copy read 4 bytes past the end of the buffer. Value histograms are now 32-bit on all targets. Replaces #135515 and #136890.A second commit fixes MIBC merging. An old (0x242) and a new (0x241) value histogram at the same IL offset were treated as the same entry, so depending on order the merge threw or kept the stale one. It now keeps the new entry.
Follow-ups / impact
MibcConfig.FormatVersionis now 1.1. Onlydotnet-pgo mergechecks it, with a warning.Validation (osx-arm64): the checked CLR build passed, and all 5
src/tests/JIT/PGOtests passed. A TieredPGO app recorded correct 32-bit samples, and Tier1 used them for the profiled memmove/SequenceEqual guard. Not run: x86 and SuperPMI.Resolves #134695
Note
This PR description was generated with GitHub Copilot.