https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110921
--- Comment #7 from Hongtao.liu <crazylht at gmail dot com> --- (In reply to 罗勇刚(Yonggang Luo) from comment #6) > MSVC also added, clang seems have optimization issue, but MSVC doesn't have > that No, I think what clang does is correct, f(int, int): # @f(int, int) test edi, edi ----------- when source operand is zero. je .LBB0_2 rep bsf eax, edi ret .LBB0_2: mov eax, 32 ret The key difference between TZCNT and BSF instruction is that TZCNT provides operand size as output when source operand is zero while in the case of BSF instruction, if source operand is zero, the content of destination operand are undefined. https://godbolt.org/z/s74dfdWP4