binaryen
binaryen copied to clipboard
OptimizeInstructions: Select => and/or in more cases
x ? 0 : y ==> z & y where z = !x
x ? y : 1 ==> z | y where z = !x
Only do this when we have z = !x
, that is, we can invert x
without adding
an actual eqz
. (Adding an eqz
would turn this from one instruction into
two, which means more work, which could be slower.)
Will be great also add this rules:
x ? x : y ==> x | y
x ? y : x ==> x & y
x, y <- 1-bit types
however with #4161 pass it will be unnecessary
This is now ready for review (I updated the top comment and finished fuzzing), but not urgent.
LGTM from my side
@kripken could you merge this?
Rewritten to use a more canonicalization approach.