[llvm] [InstCombine] Narrow the ctpop when upper bits are known zero (PR #196537)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 07:09:55 PDT 2026


================
@@ -696,6 +696,18 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
   KnownBits Known(BitWidth);
   IC.computeKnownBits(Op0, Known, &II);
 
+  // If the upper half of the bits are known zero, narrow:
+  // ctpop(x) --> zext(ctpop(trunc(x)))
+  if (BitWidth >= 64) {
----------------
RKSimon wrote:

avoid magic numbers (and could BitWidth be non-pow2?)

https://github.com/llvm/llvm-project/pull/196537


More information about the llvm-commits mailing list