16-bit cmov instructions are 1 byte longer than their 32-bit equivalents. We should promote them to 32-bit operations when possible like we do for binary operators. To accomplish this requires several steps some of which can and probably should be broken out.
We currently have support for promoting extends of 16-bit cmovs of constants to 32 or 64 bits. I've remove all of that as what I've implemented here should be more general purpose. Though I did lose the extending to 64-bit, but I don't know if that was completely necessary.
I've added X86ISD::CMOV to our target hooks for computeKnownBits and computeNumSignBits. This enables removal of zero extends and sign extends after the cmov is promoted. These parts should be committed separately.
Constant inputs to CMOV are sign extended so that computeNumSignBits will enable removal of later sign extends. I believe this is what bin op promotion does with constant inputs as well.
If we see (and (cmov X, Y)) we try to remove undemanded bits from X and Y. This allows us to turn the default sign extending of constants into zero extending if we don't need the bits. This is most important for ands that represent zext_inreg. This could be done more generically if we had SimplifyDemandedBits for target nodes. Once the unused bits are all zeroed out, computeKnownBits can try to remove the and. This can probably be committed independently as well.
I've blocked the promotion if there is a possibility of folding a load. This is what we do for other operations in IsDesirableToPromoteOp.