https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78683
Bug ID: 78683 Summary: [ppc] __builtin_ctlz code gen can be improved for -mcpu=power8 and earlier Product: gcc Version: 7.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: wschmidt at gcc dot gnu.org Target Milestone: --- For this code: unsigned r; r = (unsigned) __builtin_ctzl(v); return r; GCC on POWER produces: neg 9,3 and 3,9,3 cntlzd 3,3 subfic 3,3,63 rldicl 3,3,0,32 Two other compilers produce the following sequences: addi 4, 3, -1 andc 3, 4, 3 popcntd 3, 3 or addi r0,r3,-1 andc r0,r0,r3 cntlzd r0,r0 subfic r3,r0,64 We should probably be using the short and elegant popcntd solution.