[PATCH] D32605: Recognize CTLZ builtin

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 9 14:55:52 PDT 2017


craig.topper added a comment.

The target independent lowering code emits this for CTLZ when its not supported.  I think the popcount expands to this http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel if its not supported. So there shouldn't be a libcall unless the target is changing the default behavior.

  // for now, we do this:
  // x = x | (x >> 1);
  // x = x | (x >> 2);
  // ...
  // x = x | (x >>16);
  // x = x | (x >>32); // for 64-bit input
  // return popcount(~x);
  //
  // Ref: "Hacker's Delight" by Henry Warren


Repository:
  rL LLVM

https://reviews.llvm.org/D32605





More information about the llvm-commits mailing list