binaryen
binaryen copied to clipboard
[OptimizeInstructions] Invert sign for negative RHS constants in signed rem
i32(x) % -C => i32(x) % C
i64(x) % -C => i64(x) % C, if C != C_min
It may reduce size (however not sure) and canonicalize expression for further optimizations like (signed)x % C_pot != 0
and remove special (signed)x % -1 ==> 0
rule.
Fuzzed: ITERATION: 11165
This looks correct, but I wonder if we should look into size some more. This will increase size in some cases as negative numbers can be smaller due to how LEBs work (see here). OTOH positive numbers are more common, so I'd expect gzip to prefer positive ones. As rem is rare, this may not matter much, though.
Yes, negative denonimators quite uncommon especially those who might have benefited from negative value. Besides, it would make the logic very complicated if we take this into account
@kripken Can we merge it?
@tlively @kripken Could you merge it while it already approved?
I would be happy to merge, but I want to make sure @kripken is ok with the size question first.
I think if we do some measurements on this that would be enough. A few large real-world wasm files would be enough. I can help find some if you need that @MaxGraey
A few large real-world wasm files would be enough. I can help find some if you need that
It should be non-LLVM binaryen due to LLVM already do this canonization