https://github.com/RKSimon commented: PTAL at LowerCTPOP in X86ISelLowering.cpp - which uses a shifted active mask for this kind of thing (some of which can probably be moved to expandCTPOP). https://github.com/llvm/llvm-project/pull/221671