Repository navigation
Remove redundant fence and reload from 64-bit atomic_load_acquire - #9722
Merged
Merged
Conversation
When the atomic wrappers moved to runtime_atomics.h (#7429), the 64-bit atomic_load_acquire picked up the body of the 32-bit __sync variant after its __atomic acquire load: a full fence followed by a second, plain load that overwrites the result. That is a needless full barrier on every acquire load, and the plain reload is a non-atomic read of a shared location. Restore the plain __atomic acquire load. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9722 +/- ##
=======================================
Coverage 73.40% 73.40%
=======================================
Files 266 266
Lines 83749 83749
Branches 20573 20573
=======================================
+ Hits 61474 61480 +6
+ Misses 15808 15807 -1
+ Partials 6467 6462 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Labeling |
alexreinking
pushed a commit
that referenced
this pull request
Nov 29, 2026
) When the atomic wrappers moved to runtime_atomics.h (#7429), the 64-bit atomic_load_acquire picked up the body of the 32-bit __sync variant after its __atomic acquire load: a full fence followed by a second, plain load that overwrites the result. That is a needless full barrier on every acquire load, and the plain reload is a non-atomic read of a shared location. Restore the plain __atomic acquire load. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit d1bce45)
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.
Copilot says:
The 64-bit
atomic_load_acquireinsrc/runtime/runtime_atomics.hdoes an__ATOMIC_ACQUIREload, then__sync_synchronize(), then a second plain load*val = *addr. The last two lines are the body of the 32-bit__syncvariant. They appear to have been pasted in by mistake when the wrappers moved out ofsynchronization_common.hin #7429; before that, the 64-bit version was just the acquire load.The extra lines don't break correctness, but they cost a full barrier on every acquire load. The reload is also a non-atomic read of a location other threads write. This PR restores the single acquire load. The 32-bit variant is unchanged. Current callers are the semaphore try-acquire in
thread_pool_common.handtracing.cpp.Checklist
No new tests. This is a behavior-preserving cleanup. Validation:
tracing.cppandposix_threads.cppcompile with the runtime flags (-DBITS_64), and the IR shows a singleload atomic ... acquirewith no fence.make -j64 bin/correctness_{async,async_device_copy,async_order,parallel_nested_1,sliding_reduction,tracing,tracing_stack,tracing_bounds,tracing_broadcast}, then ran each: all passed.