Precompute removes atomic.fence in shared-memory modules

オープン
#9,369 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
53/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
c, cpp, wasm
領域
backend, compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
WebAssembly
スター
8.7k
フォーク
905
平均マージ
2日 55分
マージ済み PR(30日)
83

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

WebAssembly/binaryen のほかの issue

WebAssembly/binaryen の issue をすべて見る

似ている issue

Backend & API Design の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。