Skip to content

RemoveUnusedBrs: optimize unreachable control flow mixed with side-effecting branches #7639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jun 24, 2025

Conversation

xuruiyang2002
Copy link
Contributor

Currently wasm-opt cannot optimize unused branch complexed with side-effect operations, such as

 (func $_start
  (local $0 i32)
  (block $block
   (br_if $block
    (local.tee $0
     (i32.const 1)
    )
   )
   (br_if $block
    (i32.load
     (i32.const 0)
    )
   )
   (local.set $0
    (i32.const 0)
   )
  )
  (i32.store
   (i32.const 0)
   (local.get $0)
  )
 )

Actually, the whole block can be removed. However, O3 cannot optimize it (while O2 could).

Fixes: #7637

@xuruiyang2002

This comment was marked as resolved.

@xuruiyang2002

This comment was marked as resolved.

@xuruiyang2002
Copy link
Contributor Author

BTW: fuzzing for about one hour, and no bad news.

@kripken kripken merged commit 9bd8871 into WebAssembly:main Jun 24, 2025
16 checks passed
@xuruiyang2002 xuruiyang2002 deleted the opt_br_if_cond branch June 25, 2025 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Significant optimization regression due to failing remove unused branch
2 participants