LLVM Chapter 3 Validation
This directory contains a small LLVM IR harness for checking how current-head
opt + llc lower representative Chapter 3 power-of-two boundary idioms to
x86_64.
Run:
./run-ch3-validation.shCurrent findings:
- Alignment idioms like
round_up_8,round_up_16, andround_down_8lower well toleaplusand. x & (x - 1) == 0is recognized:is_pow2_or_zerolowers toblsrplusseteis_pow2_nonzerois canonicalized throughctpop
- Crossing-page tests are improved:
- the naive form becomes an
xorplus single compare - the Hacker’s Delight form becomes a direct unsigned compare against the remaining bytes in the page
- the naive form becomes an
- The main missed optimization is that the classic Hacker’s Delight smear
networks for
flp2andclp2are not canonicalized toctlz/bit-scan forms. Equivalentctlzformulations in the same harness lower to compactlzcnt+shrx/shlxsequences.