MaxGraey opened issue #4607:
Feature
Simple optimization which rewrite
x < 0(icmp slt_imm x, 0) tox >>> bit_size(ty) - 1(ushr_imm x, 31 | 63).Benefit
x < 0is pretty common operation. Although LLVM itself applies this rule, but some code generators / optimizers such as Binaryen (wasm-opt / wasm-pack use it) don't such peephole rewrites because replacing the constant0to31or63has a negative effect on entropy when compressing wasm module via gzip or brotli.Besides, such optimization will improve cranelift IR itself, because it will remove the finalizing
bint.i32/bint.i64aftericmp.
forushr/ushr_immit is not needed.Implementation
- Add necessary rewrite for simple_opt before this line
- Add tests for
filetests/simple_preopt/simplily32.clifandfiletests/simple_preopt/simplily64.clif
Last updated: Dec 06 2025 at 06:05 UTC