Skip to content

[Heap2Local2] Support struct and array cmpxchg - #9415

Merged
tlively merged 2 commits into
mainfrom
heap2local2-cmpxchg
Nov 23, 2026
Merged

tlively merged 2 commits into
mainfrom
heap2local2-cmpxchg

Conversation

@tlively

@tlively tlively commented Nov 21, 2026

Copy link
Copy Markdown
Member

Model struct.atomic.rmw.cmpxchg and array.atomic.rmw.cmpxchg in Heap2Local2 by linking expected and replacement origins as conditional escape edges (so replacement only escapes if expected can match a heap value at runtime) and lowering cmpxchg operations on non-escaping allocations or non-matching expected operands in Optimizer.

Model struct.atomic.rmw.cmpxchg and array.atomic.rmw.cmpxchg in Heap2Local2 by linking expected and replacement origins as conditional escape edges (so replacement only escapes if expected can match a heap value at runtime) and lowering cmpxchg operations on non-escaping allocations or non-matching expected operands in Optimizer.
@tlively
tlively requested a review from kripken November 21, 2026 03:22
std::vector<NodeId> escapingNodes;
// Tracked cmpxchg sites where an escaping expected value forces replacement
// to escape.
std::vector<CmpxchgSite> cmpxchgSites;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can't fold the cmpxchg edges into the normal graph like we did for cast edges because they are not dataflow edges at all and would have to be special-cased everywhere anyway.

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice improvements on the tests!

Comment thread src/passes/Heap2Local2.cpp Outdated
// Conditional escape adjacency list: escapeAdj[u] lists replacement
// allocations v that must escape if expected allocation u escapes in a
// cmpxchg. Lazily allocated since candidate-to-candidate cmpxchg is rare.
std::vector<std::vector<AllocId>> escapeAdj;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe

Suggested change
std::vector<std::vector<AllocId>> escapeAdj;
std::vector<SmallVector<AllocId, 1>> escapeAdj;

?

@tlively
tlively merged commit 3cb6c57 into main Nov 23, 2026
19 checks passed
@tlively
tlively deleted the heap2local2-cmpxchg branch November 23, 2026 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants