binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

OptimizeInstructions: Select => and/or in more cases

Open kripken opened this issue 2 years ago • 4 comments

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.)

kripken avatar Sep 14 '21 21:09 kripken

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

MaxGraey avatar Sep 19 '21 19:09 MaxGraey

This is now ready for review (I updated the top comment and finished fuzzing), but not urgent.

kripken avatar Oct 28 '21 18:10 kripken

LGTM from my side

MaxGraey avatar Oct 28 '21 19:10 MaxGraey

@kripken could you merge this?

MaxGraey avatar Dec 10 '21 10:12 MaxGraey

Rewritten to use a more canonicalization approach.

kripken avatar Aug 31 '22 22:08 kripken