local-cse introduces side effects via local.tee, blocking DCE in O3
维护者通常 1 天内回复
还没有人认领这个 Issue。
- #7460 来自 @xuruiyang2002 —— 已关闭,未合并
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- wasm
- 领域
- compilers
调研方向
首先,使用提供的 WebAssembly 重现 issue 中的 wasm-opt 行为,并比较 -all -O2 和 -all -O3。跟踪额外的 local-cse pass 及其 local.tee 转换,然后验证 always-false br_if 的主体是否在优化流水线之后被移除。
由索引模型根据 Issue 内容生成。
描述
Given the following code:
(module
(type $0 (func))
(type $1 (func (param i32 i32) (result i32)))
(import "External" "external_function" (func $external_function (type $0)))
(func $_start (type $1) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32) (local $4 i32) (local $7 i32) (local $8 i32) (local $11 i32) (local $13 i32)
global.get $__stack_pointer
local.set $2
local.get $2
i64.const 0
i64.store offset=1752
i32.const 4058
local.set $4
local.get $2
local.get $4
i32.add
i32.const 1
i32.add
local.set $7
i32.const 4058
local.set $8
local.get $2
local.get $8
i32.add
i32.const 1
i32.add
local.set $11
local.get $7
local.get $11
i32.ne
local.set $13
block ;; label = @1
local.get $13
i32.eqz
br_if 0 (;@1;)
call $external_function
end
unreachable)
(memory $0 259 259)
(global $__stack_pointer (mut i32) (i32.const 0))
(export "_start" (func $_start)))
wasm-opt (862aeb9) eliminates the dead br_if body by -all -O2 but can not do that by -all -O3.
After analysis, O3 performs one more local-cse than O2, thus introducing local.tee (e.g., combining local.set + local.get). However, it also introduces side effect, which blocks constant propagation and then finally blocks DCE
Specifically, through local-cse, wasm-opt transforms the condition (always false) of br_if statements from
(i32.ne
(i32.add
(i32.add
(local.get $0)
(i32.const 4058)
)
(i32.const 1)
)
(i32.add
(i32.add
(local.get $0)
(i32.const 4058)
)
(i32.const 1)
)
)
to
(i32.ne
(local.tee $2
(i32.add
(i32.add
(local.get $0)
(i32.const 4058)
)
(i32.const 1)
)
)
(local.get $2)
)
thus blocking the constant propagation, leading to DCE missed optimization.
Overall, I think it is a missed optimization.
- 主要语言
- WebAssembly
- 星标
- 8.7k
- 派生
- 893
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 90
环境准备
- 没有 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 天内回复
-
难度 4/5 3-5 天 新手友好度 47/100
WebAssembly/binaryen#9233 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 52/100
WebAssembly/binaryen#9186 ·
维护者通常 1 天内回复
-
OptimizeInstructions: `select (memory.grow 1) (memory.grow 1) c` is folded to one operand and returns the wrong result可能已有人在做 @tamaroning 于 1 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 68/100
WebAssembly/binaryen#9181 ·
维护者通常 1 天内回复
查看 WebAssembly/binaryen 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
The XMIR reader wraps an `@as` index above `Int`, so `as="α18446744073709551616"` is read as `α0`未关闭
难度 2/5 1-3 小时 新手友好度 78/100
objectionary/phino#1769 ·
维护者通常 1 天内回复
-
A `\u` in an object name breaks the Javadoc that `to-java.xsl` writes, so the class does not compile未关闭
难度 2/5 1-3 小时 新手友好度 74/100
objectionary/eo#9347 ·
维护者通常 1 天内回复
-
erdos-status-sync
难度 2/5 1-3 小时 新手友好度 65/100
google-deepmind/formal-conjectures#6920 ·
维护者通常 1 天内回复
-
area-web-js web-libraries
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 4 天内回复