Stream: git-wasmtime

Topic: wasmtime / issue #12679 [cranelift-codegen] Feature Reque...


view this post on Zulip Wasmtime GitHub notifications bot (Feb 26 2026 at 12:19):

ahqsoftwares opened issue #12679:

Feature

Currently, Cranelift's atomic instructions (atomic_load, atomic_store, atomic_rmw, and atomic_cas) are hardcoded to Sequentially Consistent (SeqCst).

Even though it is correct for the current WebAssembly Threads proposal, it results in a performance bottleneck for non-Wasm frontends like rustc_codegen_cranelift or custom JITs that might require C11-style weak memory ordering.

Proposed Change

Addition of a MemoryOrdering enum to the following:

Suggested Ordering of enum

enum MemoryOrdering {
    Relaxed,
    Acquire,
    Release,
    AcqRel,
    #[default]
    SeqCst, // Default for backward compatibility
}

Implementation

Alternatives

Please Note

I am currently only focusing on the high level IR representation. I am not much acquainted with the spefic ISA lowering logic and hence, leave it to those more familiar than I am.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 26 2026 at 20:02):

cfallin commented on issue #12679:

I'd be happy to review a PR for this. Note that Cranelift's design today would permit an ordering field to affect the lowering (causing e.g. different fences or variants of atomic instructions to actually be emitted) but would not take advantage of the weaker ordering in alias analysis or code motion, as e.g. LLVM and gcc do, because Cranelift never performs code motion on memory operations. So the actual performance gains would be marginal at best, especially e.g. on x86 where default loads/stores already have Release/Acquire semantics due to TSO.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 01 2026 at 15:58):

ahqsoftwares commented on issue #12679:

Thanks a lot for the feedback @cfallin
I am confortable in implementing the enum in CDSL and updating metadata/ISLE to carry the field.

However, I don't have the expertise to optimize the lowering so at best I would be able to alias them to the current SeqCst implementation, i.e. providing the hooks to implement the specialized fences.

Would such a PR focusing mainly on the IR Infrastructure work?


Last updated: Mar 23 2026 at 16:19 UTC