https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124838
--- Comment #4 from Xi Ruoyao <xry111 at gcc dot gnu.org> --- At -O2 (In reply to Zoltan Hidvegi from comment #3) > Sorry, I haven't realized that I can use __builtin_clzg for that, it works > great. The ? operator though expands to lzcnt/test/cmov instead of the > single lzcnt instruction, so the two are not the same. No, the produced assembly is exactly same at -O2 -mlzcnt. GCC knows lzcnt outputs 64 when the input is 0, so it optimizes the test/cmov away. See CLZ_DEFINED_VALUE_AT_ZERO in the GCC code and Internal documentation for how the target maintainers have already tell GCC this fact.
