[PATCH] D50165: [X86] Add a DAG combine for the __builtin_parity idiom used by clang to enable better codegen
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 1 15:59:15 PDT 2018
craig.topper created this revision.
craig.topper added reviewers: RKSimon, bkramer, efriedma, spatel.
Clang uses "ctpop & 1" to implement __builtin_parity. If the popcnt instruction isn't supported this generates a large amount of code to calculate the population count. Instead we can bisect the data down to a single byte using xor and then check the parity flag.
Even when popcnt is supported, its still a good idea to split 64-bit data on 32-bit targets using an xor in front of a single popcnt. Otherwise we get two popcnts and an add before the and.
I've specifically targeted this at the sizes supported by clang builtins, but we could generalize this if we think that's useful.
I can pre-commit the test cases and show only the changes here if we want.
https://reviews.llvm.org/D50165
Files:
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/parity.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50165.158656.patch
Type: text/x-patch
Size: 7160 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180801/778de46d/attachment.bin>
More information about the llvm-commits
mailing list