-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Open
Labels
backend:X86good first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contributemissed-optimization
Description
[Zig Godbolt]
[C Godbolt]
[LLVM Godbolt]
Here's some C code:
#include <stdint.h>
#include <immintrin.h>
uint32_t foo(uint8_t byte) {
uint32_t q = byte;
uint32_t acc = 0;
while (1) {
uint32_t mask = _bzhi_u32(~0u, q);
acc ^= mask;
int br = q <= 16;
q -= 16;
if (br) break;
}
return acc;
}
Compiles to: (current in red, ideal in green)
foo:
mov ecx, -1
xor eax, eax
.LBB0_1:
bzhi edx, ecx, edi
xor eax, edx
- lea edx, [rdi - 16]
- cmp edi, 16
- mov edi, edx
+ sub edi, 16
ja .LBB0_1
ret
Metadata
Metadata
Assignees
Labels
backend:X86good first issuehttps://github.com/llvm/llvm-project/contributehttps://github.com/llvm/llvm-project/contributemissed-optimization