https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78103
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target| |x86_64-*-*, i?86-*-* Status|UNCONFIRMED |NEW Version|unknown |6.2.1 Keywords| |missed-optimization Last reconfirmed| |2016-10-25 Component|tree-optimization |target CC| |rguenth at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- There isn't a find-last-set builtin thus this is a target (or RTL optimization) issue. I believe find-last-set is also computed by ffs (x & -x) so that might be a more canonical way to express this on GIMPLE? constexpr unsigned long findLastSet3(unsigned long x) { return __builtin_ffsl (x & -x); } _Z12findLastSet3m: .LFB2: .cfi_startproc movq %rdi, %rax movq $-1, %rdx negq %rax andq %rax, %rdi bsfq %rdi, %rax cmove %rdx, %rax addq $1, %rax cltq ret not really optimal either though.