https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83171
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2017-11-26 00:00:00 |2021-8-19 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- >Clang (-O2, using libstdc++) and MSVC(/O2, Visual 2017) seem to handle this >correctly. clang is definitely able to handle it. We should inline the popcount too if the target does not support popcount but that is a different bug report I had saw before. anyways here is a reduced testcase: #include <stdint.h> #include <stddef.h> size_t foo1(uint32_t value) { unsigned char t = value; return __builtin_popcount(t); } size_t foo2(uint32_t value) { unsigned char t = value; unsigned int t1 = t; return __builtin_popcountl(t1); } ----- CUT ---- Note for aarch64, it does not matter as we always zero_extend to 64bit, though I suspect there might be a way to remove the addv if we are just doing one byte popcount.