[llvm] [SDag][ARM][RISCV] Allow lowering CTPOP into a libcall (PR #101786)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 25 07:50:20 PDT 2025
s-barannikov wrote:
If I adjust `__popcountsi2` implementation a bit, I get the same issue :) It is recognized by [`tryToRecognizePopcount`](https://github.com/llvm/llvm-project/blob/19ee7ffdacd54267aa18793b31d23c9c4fb94ee6/llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp#L293).
For some functions this issue is worked around by comparing the optimized function's name with the name of the new callee and bailing out if they are the same. I can't find right away where I saw it; it wasn't done generically, only for some (or maybe just a couple) functions. We could do the same for `__popcountXi2`, but that won't help because the caller's name is different (`__sw_hweightXX`).
Even if the compiler stops generating calls to popcount as part of ctz/clz expansion, it will still recognize `__sw_hweightXX` as popcount and generate the libcall. If we want to prevent the compiler from doing that, we need a handle similar to `-fno-builtin`
or a function attribute or ...
https://github.com/llvm/llvm-project/pull/101786
More information about the llvm-commits
mailing list