Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

SimplifyLocals causes ineffective code

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
wasm
領域
compilers

調査の方向性

-O3 および -O3 -sp=simplify-locals を使用して wasm-opt で例を再現し、その後 simplify-locals のエントリーポイントと、続いて行われる条件最適化を調査します。2 回の実行で生成された WebAssembly を比較します。この入力に対する回帰テストがあり、到達可能な動作を誤って削除することなく、見逃されていた最適化が対処されていれば完了です。

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

説明

Given the following code:

(module
  (type (;0;) (func))
  (import "External" "external_function" (func $external_function (type 0)))
  (func $_start (type 0)
    i32.const 9576
    i32.load
    i32.load
    i32.load
    drop
    i32.const 9576
    i32.load
    i32.load
    i32.load
    i32.const 9576
    i32.load
    i32.load
    i32.load
    i32.gt_s
    if (result i32)  ;; label = @1
      call $external_function
      i32.const 1
    else
      i32.const 0
    end
    drop
    unreachable)
  (memory $0 258 258)
  (export "_start" (func $_start)))

For wasm-opt (c91c0520a61), -O3 -sp=simplify-locals can eliminate the unreachable code, while -O3 cannot:

 (func $_start
  (local $0 i32)
  (if
   (i32.gt_s
    (local.tee $0
     (i32.load
      (i32.load
       (i32.load
        (i32.const 9576)
       )
      )
     )
    )
    (local.get $0)
   )
   (then
    (call $external_function)
   )
  )
  (unreachable)
 )

After investigating, it is the Wasm-specific optimization simplify-locals causes the counter-intuitive code. Below is the change made by simplify-locals:

Image

As you can see, the currently wasm-opt cannot optimize the if condition on the right---it can only do that on the left, which I think it is missed optimization (It is not the simplify-locals fault...).

主要言語
WebAssembly
スター
8.6k
フォーク
885
平均マージ
2日 4時間
マージ済み PR(30日)
77

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

WebAssembly/binaryen のほかの issue

WebAssembly/binaryen の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

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

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