Stream: git-wasmtime

Topic: wasmtime / issue #4607 [Feature] Add `x < 0` -> `x >>> it...


view this post on Zulip Wasmtime GitHub notifications bot (Aug 04 2022 at 10:27):

MaxGraey opened issue #4607:

Feature

Simple optimization which rewrite x < 0 (icmp slt_imm x, 0) to x >>> bit_size(ty) - 1 (ushr_imm x, 31 | 63).

Benefit

x < 0 is 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 constant 0 to 31 or 63 has 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.i64 after icmp.
for ushr/ushr_imm it is not needed.

Implementation


Last updated: Dec 23 2024 at 12:05 UTC