[x86] Restructure the parallel bitmath lowering of popcount into
authorChandler Carruth <chandlerc@gmail.com>
Sat, 30 May 2015 03:20:55 +0000 (03:20 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 30 May 2015 03:20:55 +0000 (03:20 +0000)
commit43d1e87d73b2f5dcb749f17c08e2e023fbd7006f
treee6e2d380110f1155bf77748f5951c0528a347175
parent586c0042da5ad8883ae3e94b83b7c1a3c186e232
[x86] Restructure the parallel bitmath lowering of popcount into
a separate routine, generalize it to work for all the integer vector
sizes, and do general code cleanups.

This dramatically improves lowerings of byte and short element vector
popcount, but more importantly it will make the introduction of the
LUT-approach much cleaner.

The biggest cleanup I've done is to just force the legalizer to do the
bitcasting we need. We run these iteratively now and it makes the code
much simpler IMO. Other changes were minor, and mostly naming and
splitting things up in a way that makes it more clear what is going on.

The other significant change is to use a different final horizontal sum
approach. This is the same number of instructions as the old method, but
shifts left instead of right so that we can clear everything but the
final sum with a single shift right. This seems likely better than
a mask which will usually have to read the mask from memory. It is
certaily fewer u-ops. Also, this will be temporary. This and the LUT
approach share the need of horizontal adds to finish the computation,
and we have more clever approaches than this one that I'll switch over
to.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238635 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/vector-popcnt-128.ll
test/CodeGen/X86/vector-popcnt-256.ll