TupleOptimization: tuple swap is miscompiled
維護者通常 1 天內回覆
評估
研究方向
Start by running the provided test.wat reproducer with and without --tuple-optimization, then locate the TupleOptimization pass in Binaryen. The issue suggests comparing its lowering with Heap2Local's handling of struct.new. Done means the optimized swap returns 16, matching the unoptimized module; add a regression test for the reproducer.
由索引模型根據 Issue 內容生成。
描述
Summary
--tuple-optimization splits a tuple local into scalar locals and lowers local.set $t (tuple.make a0 a1) to $t0 = a0; $t1 = a1, in order. If an operand reads an element of $t that was already overwritten (a1 = tuple.extract 0 $t), it reads the new value:
t = (t.1, t.0) ==> $t0 = $t1; $t1 = $t0; // $t0 is already overwritten
The pass is in -O1 and above; a multivalue loop that swaps its parameters (plain wasm) is miscompiled by -O3, -Os, -Oz and -O4.
Evaluating the operands into temporaries first (as Heap2Local does for struct.new) would fix it.
Reproducer
test.wat:
(module
(func (export "f") (param $x i32) (param $y i32) (result i32)
(local $t (tuple i32 i32))
(local.set $t (tuple.make 2 (local.get $x) (local.get $y)))
(local.set $t (tuple.make 2 (tuple.extract 2 1 (local.get $t)) (tuple.extract 2 0 (local.get $t))))
(tuple.extract 2 1 (local.get $t))))
$ wasm-opt test.wat --enable-multivalue -o in.wasm
$ wasm-opt test.wat --enable-multivalue --tuple-optimization -o out.wasm
$ wasmtime run --invoke f in.wasm 16 1000
16
$ wasmtime run --invoke f out.wasm 16 1000
1000
f swaps the elements of t and returns t.1, which is the original x, so the correct result is 16. V8 gives the same results.
AI was used as part of the process of finding this issue. I have manually checked and reproduced it.
- 主要語言
- WebAssembly
- 星號
- 8.7k
- 分支
- 905
- 平均合併
- 1 天 23 小時
- 30 天內合併 PR
- 86
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
WebAssembly/binaryen 的其他 Issue
-
難度 1/5 1 小時以內 新手友好度 88/100
WebAssembly/binaryen#9135 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 半天 新手友好度 76/100
WebAssembly/binaryen#9018 · 3 則留言 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 68/100
WebAssembly/binaryen#9366 ·
維護者通常 1 天內回覆
-
難度 3/5 1-2 天 新手友好度 68/100
WebAssembly/binaryen#9365 ·
維護者通常 1 天內回覆
-
Add a pass to relax nullabilities of definitions可能已有人在做 @stevenfontanella 於 2 天前認領。 未關閉
WebAssembly/binaryen#9352 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 WebAssembly/binaryen 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 84/100
tree-sitter/tree-sitter-cpp#381 ·
-
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 1 天內回覆
-
new issue
難度 2/5 1-3 小時 新手友好度 72/100
llvm/llvm-project#240065 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 77/100
CanadaHonk/porffor#452 ·