Finally, the fold i was looking forward to :)
The legality check is muddy, i doubt i've groked the full generalization,
but it handles all the cases i care about, and can come up with:
https://rise4fun.com/Alive/26j
I.e. we can perform the fold if any of the following is true:
- The shift amount is either zero or one less than widest bitwidth
- Either of the values being shifted has at most lowest bit set
- The value that is being shifted by shl (which is not truncated) should have no less leading zeros than the total shift amount;
- The value that is being shifted by lshr (which is truncated) should have no less leading zeros than the widest bit width minus total shift amount minus one
I strongly suspect there is some better generalization, but i'm not aware of it as of right now.
For now i also avoided using actual computeKnownBits(), but restricted it to constants.
Use ´WidestBitWidth´