Precompute removes atomic.fence in shared-memory modules

Geschlossen
#9,369 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@stevenfontanella arbeitet bereits daran.

Seit 10.11.2026.

  • #9379 von @stevenfontanella — gemerged

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
53/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
c, cpp, wasm
Bereich
backend, compilers

Rechercherichtung

Start by tracing how --precompute handles atomic.fence and how EffectAnalyzer marks shared-memory reads and writes; the issue does not name implementation files or tests. Reproduce with the provided C example and wasm-opt --precompute --enable-threads, then compare the output with --vacuum alone. Done when precompute preserves the fence in the shared-memory case.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

wasm-opt version 133 (version_133-96-ga631c1445), from emsdk.

--precompute (and so -O1 and above) replaces atomic.fence with nothing, even with --enable-threads and a shared memory. --vacuum alone keeps it. EffectAnalyzer marks the fence as reading/writing shared memory, so Precompute seems to skip that check.

Repro:

int x, y;
__attribute__((export_name("st"))) void st(int v) {
  x = v; __atomic_thread_fence(__ATOMIC_SEQ_CST); y = 1;
}
clang --target=wasm32 -O2 -matomics -mbulk-memory -c f.c -o f.o
wasm-ld --no-entry --shared-memory --import-memory --max-memory=1048576 f.o -o f.wasm
wasm-opt --precompute --enable-threads f.wasm -o g.wasm
llvm-objdump -d f.wasm | grep -c atomic.fence   # 1
llvm-objdump -d g.wasm | grep -c atomic.fence   # 0

Same result with -O1, -O2, -O3, -Os and with --detect-features; -O0 keeps it.

Impact: in our emulator a guest FENCE is compiled to atomic.fence; after wasm-opt the engine had none, and a producer/consumer ring between threads read stale bytes (intermittent aborts on ARM64 Chrome). Using an atomic.rmw.or seq_cst on a dummy cell instead survives -O3.

Vorherrschende Sprache
WebAssembly
Sterne
8.7k
Forks
905
Ø Merge
2 T. 1 Std.
Gemergte PRs (30 T.)
91

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus WebAssembly/binaryen

Alle Issues in WebAssembly/binaryen

Ähnliche Issues

Weitere Issues zu Backend & API Design

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.