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

            Bug ID: 106471
           Summary: Strange code generation for __builtin_ctzl()
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: torva...@linux-foundation.org
  Target Milestone: ---

So this actually started out as a clang issue report about bad inline asm input
argument behavior at

   https://github.com/llvm/llvm-project/issues/56789

but as part of that I was looking at __builtin_ctzl() and while gcc DTRT for
the inline asm version we use in the kernel, the builtin acts very oddly
indeed.

IOW, this code:

        unsigned long test(unsigned long arg)
        {
                return __builtin_ctzl(arg);
        }

generates this odd result with 'gcc -O2 -S':

        xorl    %eax, %eax
        rep bsfq        %rdi, %rax
        cltq
        ret

where the xor and the cltq both just confuse me.

Reply via email to