https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88959
Bug ID: 88959 Summary: Unnecessary xor before bsf/tzcnt Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: bugzi...@poradnik-webmastera.com Target Milestone: --- [code] int test(int x) { return __builtin_ctz(x); } [/code] gcc 4.9.1 with -O3 produces this: [asm] test(int): rep bsf eax, edi ret [/asm] And this with -O3 -mbmi: [asm] test(int): tzcnt eax, edi ret [/asm] gcc 4.9.2 and newer (including gcc 9) produces this for both cases: [asm] test(int): xor eax, eax rep bsf eax, edi ret [/asm] [asm] test(int): xor eax, eax tzcnt eax, edi ret [/asm] This extra xor instruction is not needed here.