[llvm] [InstCombine] Fold `ctpop(X) eq/ne 1` if X is non-zero (PR #67268)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 25 19:47:52 PDT 2023
dtcxzyw wrote:
> This fold goes against the usual direction in IR, and in particular conflicts with this generic fold:
>
> https://github.com/llvm/llvm-project/blob/bb764eccf8053244d64270df29c2e0bd3606f6c0/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L6207-L6210
>
> This is risky and can easily lead to infinite loops. I think we won't get one right now because KnownBits for ctpop is a bit weak (
> https://github.com/llvm/llvm-project/blob/d3505c28a770fabd77d7483afbca383d453bef02/llvm/lib/Analysis/ValueTracking.cpp#L1560
>
> ), but if it was later strengthened and e.g. inferred KnownBits `...0?1` then we could run into an infinite compile loop at that point.
Can we canonicalize `ctpop(X) <u 2` into `ctpop(X) == 1` in InstCombine and do inverse transform in CodeGenPrepare?
https://github.com/llvm/llvm-project/pull/67268
More information about the llvm-commits
mailing list