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

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 08:04:23 PDT 2019


spatel added inline comments.


================
Comment at: llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp:269-271
+  bool IsType32 = I.getType()->isIntegerTy(32);
+  uint16_t FinalShiftConst = IsType32 ? 24 : 56;
+  uint64_t MulConst = IsType32 ? 0x01010101 : 0x0101010101010101;
----------------
spatel wrote:
> This might actually be easier to read if generalized for more bitwidths. Can we use APInt and handle power-of-2 sizes from 8- to 128-bit?
> http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
For reference, we know it's safe to do that transform more generally because the backend handles the expansion back to this pattern more generally:
https://github.com/llvm-mirror/llvm/blob/master/lib/CodeGen/SelectionDAG/TargetLowering.cpp#L5923

(That expansion is why it is safe to do this transform in IR without a TTI hook in the first place; we don't expect any regressions because we should reverse the transform.)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D68189/new/

https://reviews.llvm.org/D68189





More information about the llvm-commits mailing list