Skip to content

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

Merged
kripken merged 11 commits intoWebAssembly:mainfrom
xuruiyang2002:fallthrough_lt_u
Apr 24, 2025
Merged

Use fallthrough in optimizeInstructions to further optimize (unsigned)x < 0 ==> i32(0)#7480
kripken merged 11 commits intoWebAssembly:mainfrom
xuruiyang2002:fallthrough_lt_u

Conversation

@xuruiyang2002
Copy link
Copy Markdown
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

Comment thread src/passes/OptimizeInstructions.cpp Outdated
Comment thread src/passes/OptimizeInstructions.cpp Outdated
Comment thread src/passes/OptimizeInstructions.cpp Outdated
@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