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

            Bug ID: 95529
           Summary: Failure to reuse flags generated by trailing zeros
                    instruction for cmovcc
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

int f(int x)
{
    return x == 0 ? 24 : ffs(x) - 1;
}

With -O3, LLVM outputs this :

f(int): # @f(int)
  bsf ecx, edi
  mov eax, 24
  cmovne eax, ecx
  ret

GCC outputs this :

f(int):
  xor eax, eax
  mov edx, 24
  rep bsf eax, edi
  test edi, edi
  cmove eax, edx
  ret

The `test` can be eliminated here.

Reply via email to