[llvm-bugs] [Bug 47193] New: Missed btc opportunities
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Aug 16 17:05:29 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47193
Bug ID: 47193
Summary: Missed btc opportunities
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, spatel+llvm at rotateright.com
uint16_t toggle16(uint16_t num, uint16_t bit) {
num ^= 1ULL << bit;
return num;
}
uint32_t toggle32(uint32_t num, uint32_t bit) {
num ^= 1ULL << bit;
return num;
}
uint64_t toggle64(uint64_t num, uint32_t bit) {
num ^= 1ULL << bit;
return num;
}
uint64_t case1(unsigned long num, uint64_t bit)
{
num ^= 1U << bit;
return num;
}
uint64_t case2(unsigned long num, uint64_t bit)
{
num ^= 1UL << bit;
return num;
}
Clang:
toggle16: # @toggle16
mov ecx, esi
mov eax, 1
shl rax, cl
xor eax, edi
ret
toggle32: # @toggle32
mov ecx, esi
mov eax, 1
shl rax, cl
xor eax, edi
ret
toggle64: # @toggle64
mov rax, rdi
btc rax, rsi
ret
case1(unsigned long, unsigned long): #
@case1(unsigned long, unsigned long)
mov rcx, rsi
mov eax, 1
shl eax, cl
xor rax, rdi
ret
case2(unsigned long, unsigned long): #
@case2(unsigned long, unsigned long)
mov rax, rdi
btc rax, rsi
ret
MSVC can catch all cases and produce btc.
https://gcc.godbolt.org/z/oE9qdz
--
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/20200817/01446e17/attachment-0001.html>
More information about the llvm-bugs
mailing list