[llvm-bugs] [Bug 50187] New: LLVM prefer lzcnt too strongly - extra computation required
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Apr 30 13:02:50 PDT 2021
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: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, pengfei.wang at intel.com,
spatel+llvm at rotateright.com
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210430/2b790897/attachment.html>
More information about the llvm-bugs
mailing list