Skip to content

Add a "relaxed" memory order - #8984

Merged
tlively merged 2 commits into
relaxed-memory-featurefrom
relaxed-memory-order
Aug 12, 2026
Merged

Add a "relaxed" memory order#8984
tlively merged 2 commits into
relaxed-memory-featurefrom
relaxed-memory-order

Conversation

@tlively

@tlively tlively commented Aug 11, 2026

Copy link
Copy Markdown
Member

The memory order is not the C++ relaxed memory order, but rather the slightly stronger load-store ordered memory order, which prevents out-of-thin-air values by forbidding earlier atomic loads from being reordered past later atomic stores. This makes it impossible to construct the self-justifying causality cycle that gives rise to out-of-thin-air values. The name of the memory order in both the implementation and the text format is likely to change in the future to become more descriptive.

The memory order is not the C++ relaxed memory order, but rather the slightly stronger load-store ordered memory order, which prevents out-of-thin-air values by forbidding earlier atomic loads from being reordered past later atomic stores. This makes it impossible to construct the self-justifying causality cycle that gives rise to out-of-thin-air values. The name of the memory order in both the implementation and the text format is likely to change in the future to become more descriptive.
@tlively
tlively requested a review from a team as a code owner August 11, 2026 03:58
@tlively
tlively requested review from stevenfontanella and removed request for a team August 11, 2026 03:58
Comment thread src/ir/effects.h
}
// Shared location accesses cannot be reordered after (but may be able to be
// reordered before) release stores.
if (other.writeOrder >= MemoryOrder::AcqRel &&

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.

Looks like this was a bug before the MemoryOrder enum ordering changed in this PR? Ditto for line 381. Currently before this PR AcqRel > SeqCst.

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.

Yeah, thankfully I think the bug was harmless because we fell through to the explicit handling of MemoryOrder::SeqCst below, which still gave us the correct behavior.

@stevenfontanella stevenfontanella 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.

Looks like the atomics.js test fails on the emscripten CI, is that related to this change? And second, do we plan to add this to the fuzzer and C + JS APIs in a future PR?

@tlively

tlively commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

Yeah, this PR had attempted to add support to the JS API, but 1) the syntax was wrong and 2) support was missing in the C API. Both are fixed in the last commit.

@tlively
tlively merged commit d8c6b2a into main Aug 12, 2026
16 checks passed
@tlively
tlively deleted the relaxed-memory-order branch August 12, 2026 06:18
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