[llvm-bugs] [Bug 37460] New: Missed rotate right optimization
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon May 14 13:27:33 PDT 2018
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: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180514/882a3e95/attachment-0001.html>
More information about the llvm-bugs
mailing list