LLVM Chapter 5 reductions
1. Hacker’s Delight popcount network not canonicalized to ctpop
File: popcount_hd_to_ctpop.ll
Issue:
- LLVM does not canonicalize the classic Hacker’s Delight parallel popcount
network to
llvm.ctpop. - On x86_64 with POPCNT available, this misses a direct lowering to
popcntl/popcntq.
Observed current-head behavior:
pop32_hdstays as the arithmetic tree.pop64_hdstays as the arithmetic tree.
Expected x86_64 shape:
popcntl %edi, %eax
retqand
popcntq %rdi, %rax
retqSuggested bug report title:
InstCombine misses ctpop canonicalization for Hacker's Delight parallel popcount idiom
2. x &= x - 1 popcount loop not replaced by ctpop
File: popcount_loop_to_ctpop.ll
Issue:
- LLVM partially strength-reduces the loop body to
blsr, but does not replace the whole counting loop withctpop.
Observed current-head behavior:
xorl %eax, %eax
testl %edi, %edi
je ...
.Lloop:
incl %eax
blsrl %edi, %edi
jne .Lloop
retqCaveat:
- This is a weaker bug-report candidate than the parallel popcount network.
- Loop idiom recognition here may be considered optional unless there is an established canonicalization policy for this specific pattern.