https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110921

--- Comment #8 from 罗勇刚(Yonggang Luo) <luoyonggang at gmail dot com> ---
(In reply to Hongtao.liu from comment #7)
> No, I think what clang does is correct,

Thanks, yeap, according to https://github.com/llvm/llvm-project/issues/64477
I think clang did it well.

GCC also needs handling the following code properly

```c
#ifdef _MSC_VER
#include <intrin.h>
__forceinline void
unreachable() {__assume(0);}
#else
#include <x86intrin.h>
inline __attribute__((always_inline)) void
unreachable() {
#if defined(__INTEL_COMPILER)
    __assume(0);
#else
    __builtin_unreachable();
#endif
}
#endif

int f(int a)
{
    if (a == 0) {
      unreachable();
    }
    return _tzcnt_u32   (a);
}

```
According to https://godbolt.org/z/T9axzaPqj

gcc with `-O2 -mbmi -m32` option compiled to
```asm
f(int):
        xor     eax, eax
        tzcnt   eax, DWORD PTR [esp+4]
        ret
```

There is a redundant xor instrunction,
Without `-mbmi` option, gcc can not compile and all other three compiler
can compile.
This issue still make sense, gcc can fixes it in Clang's way

Reply via email to