Skip to content

PGO: make value histograms 32-bit on all targets - #136895

Merged
lewing merged 2 commits into
mainfrom
lewing-pgo-valuehistogram-32bit
Nov 4, 2026
Merged

lewing merged 2 commits into
mainfrom
lewing-pgo-valuehistogram-32bit

Conversation

@lewing

@lewing lewing commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

This PR uses @EgorBo's fix from #136890 (comment); his commit is cherry-picked as-is. ValueHistogram asked 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 from countsOffset (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

  • Value-histogram records in existing MIBC and R2R data are ignored until retrained. They don't crash.
  • MibcConfig.FormatVersion is now 1.1. Only dotnet-pgo merge checks it, with a warning.
  • The JIT-EE GUID bump means SuperPMI collections need refreshing.
  • Truncating values to 32 bits is safe: the importer only uses a profiled value after a full-width range check.
  • release/9.0 and release/10.0 have the same bug; servicing is up to the maintainers.

Validation (osx-arm64): the checked CLR build passed, and all 5 src/tests/JIT/PGO tests 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.

EgorBo and others added 2 commits November 2, 2026 21:13
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]>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging @dotnet/jit-contrib for JIT-EE GUID update

@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 Nov 3, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@lewing
lewing merged commit f856ecc into main Nov 4, 2026
117 of 119 checks passed
@lewing
lewing deleted the lewing-pgo-valuehistogram-32bit branch November 4, 2026 15:13
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 6, 2026
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.

Crash: access violation in coreclr!PgoManager::getPgoInstrumentationResults during tier-1 background JIT (Windows x86)

3 participants