Skip to content

Use fallthrough in optimizeInstructions to further optimize (unsigned)x < 0 ==> i32(0) #7480

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 11 commits into from
Apr 24, 2025

Conversation

xuruiyang2002
Copy link
Contributor

Currently, wasm-opt cannot optimize the code as expected: (unsigned)x < 0 ==> i32(0).

(i32.lt_u
 (i32.load $0 (i32.const 0) )
 (block (result i32)
  (i32.store $0
   (i32.const 0)
   (i32.const 0)
  )
  (i32.const 0)
 )
)

It should have been optimized after merge-blocks, as the store could have been hoisted. However, the load and store cannot be reordered, preventing wasm-opt from doing so.

This can be addressed in optimizeInstructions by using fallthrough to hoist the constant zero, enabling further optimizations.

Fixes: #7455

@kripken kripken merged commit 456e573 into WebAssembly:main Apr 24, 2025
15 checks passed
@xuruiyang2002 xuruiyang2002 deleted the fallthrough_lt_u branch April 25, 2025 01:16
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.

[Unhoisted] [Binary] [Should fallthrough] load & store order affects the constant propagation in binaryOp
2 participants