Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

local-cse introduces side effects via local.tee, blocking DCE in O3

未关闭
#7,440 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 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 模板
  • 阅读贡献指南

从这里开始

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

WebAssembly/binaryen 的其他 Issue

查看 WebAssembly/binaryen 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 发到你的邮箱

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