[llvm] [InstCombine] Fold the `log2_ceil` idiom (PR #76661)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 2 03:15:53 PST 2024
================
@@ -1730,6 +1730,28 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
I, Builder.CreateIntrinsic(Intrinsic::ctpop, {I.getType()},
{Builder.CreateOr(A, B)}));
+ // Fold the log2_ceil idiom:
+ // zext(ctpop(A, true) >u/!= 1) + (ctlz(A) ^ (BW - 1)) --> BW - ctlz(A - 1)
+ // TODO: Add one-use checks?
----------------
nikic wrote:
I'd add the one-use checks along the ctlz path, so that we at worst replace one ctlz with another.
https://github.com/llvm/llvm-project/pull/76661
More information about the llvm-commits
mailing list