Skip to content

write barriers: declare that they read their argument memory - #63463

Merged
vchuravy merged 1 commit into
masterfrom
vc/effects-2-barrier-argmem
Oct 5, 2026
Merged

vchuravy merged 1 commit into
masterfrom
vc/effects-2-barrier-argmem

Conversation

@vchuravy

@vchuravy vchuravy commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Second of a 4-PR stack re-landing #61394: #63462 → #63463 → #63464 → #63465.

getWriteBarrierAttributes currently declares the barrier intrinsics memory(inaccessiblemem: readwrite). This adds argmem: read: the barrier does inspect the parent's and children's headers, and, more importantly, reading the slot's memory pins the guarded store above its own barrier. Once calls may carry narrowed memory effects (#63464), that is what prevents LLVM from sinking a store past a later safepoint that has meanwhile unqueued the parent object from the remembered set — one of the concerns raised in the #62697 discussion.

Today every Julia call is memory(readwrite) and pins stores by itself, so this has no effect on master's optimization output beyond forbidding a reordering that was never desirable.

Note for reviewers: JuliaLICM already hoists loop-invariant write barriers out of loops (leaving the store inside, with safepoints in between). That is sound because the stored value stays rooted across the in-loop safepoints and survivors are promoted to old (gc-stock.c, bits = GC_OLD; // promote), so the real invariant is "the stored value is live across the safepoint", not store/barrier adjacency. This PR does not change that.

🤖 Generated with Claude Code

@vchuravy
vchuravy added this pull request to stack #63466 September 28, 2026 17:00
@vchuravy vchuravy added compiler:codegen Generation of LLVM IR and native code GC Garbage collector labels Sep 28, 2026
@vchuravy
vchuravy marked this pull request as ready for review October 3, 2026 02:19
@vchuravy
vchuravy force-pushed the vc/effects-2-barrier-argmem branch from 1d2eeef to 9ba1e08 Compare October 3, 2026 02:21
@vchuravy
vchuravy requested a review from oscardssmith October 3, 2026 02:22
Base automatically changed from vc/effects-1-safepoint-marker to master October 5, 2026 05:40
The barrier inspects the parent's and children's headers, and it must
stay ordered after the store it guards. Declaring argmem reads pins a
store above its own barrier, so once calls may carry narrowed memory
effects a store can no longer be sunk past a later safepoint that
unqueues the parent object.

JuliaLICM's barrier hoisting is unaffected: it relies on the stored
value staying live across in-loop safepoints and survivors being
promoted to old, not on the store/barrier adjacency.

Assisted-by: Claude Code (Fable 5.1)
@vchuravy
vchuravy force-pushed the vc/effects-2-barrier-argmem branch from 9ba1e08 to d721f58 Compare October 5, 2026 05:40
@vchuravy
vchuravy merged commit ea074bc into master Oct 5, 2026
11 checks passed
@vchuravy
vchuravy deleted the vc/effects-2-barrier-argmem branch October 5, 2026 10:27
xal-0 pushed a commit that referenced this pull request Oct 6, 2026
write barriers: declare that they read their argument memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:codegen Generation of LLVM IR and native code GC Garbage collector

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant