https://bugs.llvm.org/show_bug.cgi?id=37460
Bug ID: 37460
Summary: Missed rotate right optimization
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedb...@nondot.org
Reporter: david.bolvan...@gmail.com
CC: llvm-bugs@lists.llvm.org
Hello,
LLVM doesn't optimize rotate right operation to ror x86 instruction for the
following case:
typedef struct { uint64_t state; uint64_t inc; } pcg32_random_t;
uint32_t pcg32_random_r(pcg32_random_t* rng) {
uint64_t oldstate = rng->state;
rng->state = oldstate * 6364136223846793005ULL + (rng->inc|1);
uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
uint32_t rot = oldstate >> 59u;
return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
}
Clang generates:
pcg32_random_r: # @pcg32_random_r
mov rcx, qword ptr [rdi]
mov rax, qword ptr [rdi + 8]
movabs rdx, 6364136223846793005
imul rdx, rcx
or rax, 1
add rax, rdx
mov qword ptr [rdi], rax
mov rax, rcx
shr rax, 18
xor rax, rcx
shr rax, 27
shr rcx, 59
mov edx, eax
shr edx, cl
neg ecx
shl eax, cl
or eax, edx
ret
Better code, generated from GCC:
pcg32_random_r:
mov rcx, QWORD PTR [rdi]
mov rdx, QWORD PTR [rdi+8]
movabs rax, 6364136223846793005
imul rax, rcx
or rdx, 1
add rax, rdx
mov QWORD PTR [rdi], rax
mov rax, rcx
shr rax, 18
xor rax, rcx
shr rcx, 59
shr rax, 27
ror eax, cl
ret
Source:
https://www.reddit.com/r/rust/comments/8jeybi/rust_does_not_rotate_or_rather_llvm/
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs