https://bugs.llvm.org/show_bug.cgi?id=50187

            Bug ID: 50187
           Summary: LLVM prefer lzcnt too strongly - extra computation
                    required
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

long long clz64(long long num) {
  return 63LL - __builtin_clzll(num | 1);
}

int clz32(unsigned num) {
  return 31 - __builtin_clz(num | 1);
}

int clz32_a(unsigned num) {
  return 31 - __builtin_clz(num);
}


LLVM -march=haswell -O3 

clz64(long long):                              # @clz64(long long)
        or      rdi, 1
        lzcnt   rax, rdi
        xor     rax, 63
        ret
clz32(unsigned int):                              # @clz32(unsigned int)
        or      edi, 1
        lzcnt   eax, edi
        xor     eax, 31
        ret
clz32_a(unsigned int):                            # @clz32_a(unsigned int)
        lzcnt   eax, edi
        xor     eax, 31
        ret

GCC -march=haswell -O3 
clz64(long long):
        or      rdi, 1
        bsr     rax, rdi
        ret
clz32(unsigned int):
        or      edi, 1
        bsr     eax, edi
        ret
clz32_a(unsigned int):
        bsr     eax, edi
        ret


https://gcc.godbolt.org/z/r4bYfocKG

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to