https://bugs.llvm.org/show_bug.cgi?id=41782
Bug ID: 41782
Summary: Deduce memcpy copy range
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
bool foo(int *a, int *b, unsigned n) {
memcpy(a, b, 8); // memcpy expanded
return a == b;
}
foo(int*, int*, unsigned int): # @foo(int*, int*,
unsigned int)
mov rax, qword ptr [rsi]
mov qword ptr [rdi], rax
cmp rdi, rsi
sete al
ret
bool foo1(int *a, int *b, unsigned n) {
n = (n % 9);
memcpy(a, b, n);
return a == b;
}
bool foo2(int *a, int *b, unsigned n) {
while (n > 8) {
--n;
}
memcpy(a, b, n);
return a == b;
}
Clang emits memcpy call in foo1 and foo2, Clang does not expand it as in the
"foo" case, but it should.
foo1(int*, int*, unsigned int): # @foo(int*, int*,
unsigned int)
push r14
push rbx
push rax
mov r14, rsi
mov rbx, rdi
mov eax, edx
imul rax, rax, 954437177
shr rax, 33
lea eax, [rax + 8*rax]
sub edx, eax
call memcpy
cmp rbx, r14
sete al
add rsp, 8
pop rbx
pop r14
ret
foo2(int*, int*, unsigned int): # @foo(int*, int*,
unsigned int)
push r14
push rbx
push rax
mov r14, rsi
mov rbx, rdi
cmp edx, 8
mov eax, 8
cmovae edx, eax
call memcpy
cmp rbx, r14
sete al
add rsp, 8
pop rbx
pop r14
ret
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs