Precompute removes atomic.fence in shared-memory modules

未关闭
#9,369 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 分钟
30 天内合并 PR
83

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

WebAssembly/binaryen 的其他 Issue

查看 WebAssembly/binaryen 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。