[PATCH] D68189: [InstCombine] recognize popcount implemented in hacker's delight.

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 29 00:57:10 PDT 2019


shchenz created this revision.
shchenz added reviewers: spatel, lebedev.ri, RKSimon, hfinkel, nemanjai.
Herald added subscribers: llvm-commits, steven.zhang, wuzish, hiraditya.
Herald added a project: LLVM.

Try to recognize below popcount implemented in hacker's delight:

  int popcount32(unsigned i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = ((i + (i >> 4)) & 0x0F0F0F0F);
    return (i * 0x01010101) >> 24; 
  }

This helps platforms which support harware popcount instruction(eg: PowerPC) get some gain for benchmark deepsjeng of cpu2017.
Maybe we need to add `TargetTransformInfo` in `InstCombiner` to make sure this combination only happens when `getPopcntSupport` is true.


https://reviews.llvm.org/D68189

Files:
  llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
  llvm/test/Transforms/InstCombine/popcount.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68189.222311.patch
Type: text/x-patch
Size: 5107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190929/ce748af7/attachment.bin>


More information about the llvm-commits mailing list