E.g. ```wat (i32.gt_u (i32.shr_u (local.get $0) (i32.const 1) ) (i32.const 100) ) =-> (i32.gt_u (local.get $0) (i32.const 201) ) ``` Instead of dividing by 2 and then comparing, we can compare the original value. More variations: add a constant, or both add and multiply/divide. Found by the superoptimizer https://github.com/WebAssembly/binaryen/pull/4994 (for comparison to other findings: rule `#8`, benefit `30492`).
Activity
kripken commentedon Sep 2, 2022
Another example from rule
#10:kripken commentedon Sep 2, 2022
This also happens with floats, though there we may need fast-math, e.g.
(rule #21)
kripken commentedon Sep 6, 2022
Another example:
The add's left operand is less than 32 bits, so it cannot overflow even with an added 8, and so
x + 8 >= 65535can be turned intox >= 65527.edit: This and related things seem to be the top superoptimizer finding for Java and Dart, followed by #5008 (comment)
OptimizeInstructions: Optimize comparisons with an added offset (#5025)
kripken commentedon Sep 13, 2022
All comparisons
<, >=, etcshould be handled with+. That leaves things like shifts, and float operations, as mentioned above.