Skip to content

-O3 Regression: OptimizeInstructions for bool(x) | 1 ==> 1 Skips Side-Effecting expr #7477

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

Closed
xuruiyang2002 opened this issue Apr 10, 2025 · 0 comments · Fixed by #7478
Closed

Comments

@xuruiyang2002
Copy link
Contributor

Given the following code:

(module
  (import "External" "external_function" (func $external_function ))
  (func $_start  (result i32)
    i32.const 0
    i32.const 0
    call $func
    )
  (func $func(param $1 i32) (param $2 i32) (result i32)
    call $foo
    i32.const 1
    i32.and
    local.set $2
    i32.const 0
    local.set $1
    local.get $2
    i32.const 1
    i32.or
    if (result i32)  ;; label = @1
      local.get $1
    else
      call $external_function
      i32.const 0
    end)
  (func $foo (result i32)
    i32.const 0
    i32.load)
  (memory $0 258 258)
  (export "_start" (func $_start)))

wasm-opt (c528c7e) can eliminate deduce the condition to be true by -all -O2, however, can not by -all -O3. Thus blocking the DCE of the false branch.

Analysis: probably the issues lies in OptimizeInstructions, the rule for bool(x) | 1 ==> 1. Currently wasm-opt cannot handle x with side-effect.

Fix: use any instead of pure.

@xuruiyang2002 xuruiyang2002 changed the title -O3 Regression: OptimizeInstructions for bool(x) | 1 ==> -1 Skips Side-Effecting expr -O3 Regression: OptimizeInstructions for bool(x) | 1 ==> 1 Skips Side-Effecting expr Apr 10, 2025
xuruiyang2002 added a commit to xuruiyang2002/binaryen that referenced this issue Apr 10, 2025
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 a pull request may close this issue.

1 participant