This is an archive of the discontinued LLVM Phabricator instance.

[X86] Enable CMOV i16 to be promoted to i32 as much as possible
AbandonedPublic

Authored by craig.topper on Oct 6 2017, 12:35 AM.

Details

Reviewers
RKSimon
spatel
zvi
Summary

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.

Diff Detail

Event Timeline

craig.topper created this revision.Oct 6 2017, 12:35 AM
craig.topper retitled this revision from [ to [X86] Enable CMOV i16 to be promoted to i32 as much as possible.Oct 6 2017, 12:50 AM
craig.topper edited the summary of this revision. (Show Details)
craig.topper added reviewers: RKSimon, spatel, zvi.
craig.topper added a subscriber: llvm-commits.
craig.topper abandoned this revision.Oct 9 2017, 1:32 PM

I've already committed part of this and there's a couple bugs in this. Abandoning and will submit a new patch once I have the kinks worked out.