[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)
commitc2e400de83d6989ec7abd1a40bb07740b47a735d
treee3419b13c22ad3872e2da6f6d1f547240ae53dd0
parent13760bd152b6c28ffa38ab1c74e6a6a2e52a3a30
[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.

llvm-svn: 238635
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/vector-popcnt-128.ll
llvm/test/CodeGen/X86/vector-popcnt-256.ll