Skip to content

Record value number equivalences from CSE - #136932

Draft
NinoFloris wants to merge 3 commits into
dotnet:mainfrom
NinoFloris:jit/cse-vn-equivalence-store
Draft

NinoFloris wants to merge 3 commits into
dotnet:mainfrom
NinoFloris:jit/cse-vn-equivalence-store

Conversation

@NinoFloris

@NinoFloris NinoFloris commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This is a zero-diff PR.

CSE rewrites a use's conservative value number to its reaching definition's, while nodes that carried the old number keep it. InsertUseIntoSsa already works around this for one fact, carrying checked-bound membership across the rewrite by hand. #136840 hit the same issue as null checks that survived a copy of the receiver. It recovered the identity by walking SSA copies at the lookup. Exact-type facts on a copied receiver and range facts on a captured bound lose track through CSE the same way.

This PR begins to record the rewrite as an equivalence in the value number store: in a small union-find over rewritten numbers, empty for methods where no use changed, with the reaching definition's number as the 'representative' VN. Nothing consults it yet and the checked-bound transfer stays as it is. A follow-up keys assertions by the representative.

It is recorded exactly when CSE merges two loads into one. A reloaded heap field gets a fresh conservative number because nothing has decided yet that the loads can be one (fgValueNumberTree, field loads). Only the one rewrite site (InsertUseIntoSsa) makes them equal, so facts never cross between loads that stayed separate.

@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
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member 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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

CSE rewrites a use's conservative value number to its reaching definition's. Other nodes that carried the old value number, such as copies made before CSE, keep it, so facts created under one number are invisible under the other.

Record the rewrite as a value number equivalence. The value number store keeps a union-find over rewritten numbers, empty for methods where no use changed. The representative is the number that says the most about the value: a constant, else a phi definition or a function, else the reaching definition's number; a constant never keys the map. Nothing consults it yet: the existing checked-bound transfer stays as it is, so this produces no code differences. A follow-up keys assertions by the representative.
About one method in nine records a rewrite, so the inline buckets of an embedded table would be carried by every value number store for nothing. Keep a pointer and allocate on the first record.
Most lookups are for numbers without a recorded equivalence, so a bit per number answers them without hashing, and the list behind it holds only the few pairs a method records, scanned in place. GrowableBitSet in bitvec.h is BitVec's shape without traits or a size up front, for a set whose index space is still being allocated while it fills.
@NinoFloris
NinoFloris force-pushed the jit/cse-vn-equivalence-store branch from 88d9031 to b92d0ab Compare November 5, 2026 00:30

This branch has not been deployed

No deployments
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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant