[llvm-bugs] [Bug 38717] New: Suboptimal 128 bit integer division in loop
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Aug 27 02:47:40 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38717
Bug ID: 38717
Summary: Suboptimal 128 bit integer division in loop
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
int main(void)
{
const __int128 m = 3329589384618324948;
__int128 n = m * m;
enum { base = 10, max_width = 39 };
char a[max_width + 1] = { '\0' };
char *p = a + max_width;
for (; n != 0; n /= base)
*--p = (char)('0' + n % base);
printf("%s\n", p);
}
Clang trunk with O3:
.LBB0_1:
mov edx, 10
xor ecx, ecx
mov rdi, r15
mov rsi, r14
call __divti3
mov rbx, rax
mov r12, rdx
lea eax, [rax + rax]
lea eax, [rax + 4*rax]
mov ecx, r15d
sub ecx, eax
add cl, 48
mov byte ptr [r13], cl
mov edx, 10
xor ecx, ecx
mov rdi, rbx
mov rsi, r12
call __modti3
add al, 48
mov byte ptr [r13 - 1], al
mov edx, 100
xor ecx, ecx
mov rdi, r15
mov rsi, r14
call __divti3 <---- elide it like GCC did?
mov r15, rax
mov r14, rdx
add rbx, 9
adc r12, 0
add r13, -2
cmp rbp, rbx
mov eax, 0
sbb rax, r12
jb .LBB0_1
lea rdi, [rsp + 1]
call puts
xor eax, eax
add rsp, 40
pop rbx
pop r12
pop r13
pop r14
pop r15
pop rbp
ret
GCC:
.L2:
mov rbx, rdx
mov rdi, r13
xor ecx, ecx
mov edx, 10
mov rsi, rbx
sub rbp, 1
call __modti3
mov rdi, r13
mov edx, 10
xor ecx, ecx
add eax, 48
mov rsi, rbx
mov BYTE PTR [rbp+0], al
call __divti3
mov r13, rax
cmp rbp, r12
jne .L2
mov rdi, rbp
call puts
add rsp, 56
xor eax, eax
pop rbx
pop rbp
pop r12
pop r13
ret
--
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/20180827/0c002095/attachment-0001.html>
More information about the llvm-bugs
mailing list