[llvm-bugs] [Bug 39844] New: Field ordering causes extra memcpy
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Nov 29 15:14:09 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=39844
Bug ID: 39844
Summary: Field ordering causes extra memcpy
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: jmuizelaar at mozilla.com
CC: llvm-bugs at lists.llvm.org
The following program:
#include <stdlib.h>
struct SV {
size_t capacity;
size_t disc;
size_t data[40];
static SV make() {
SV ret;
ret.capacity = 0;
ret.disc = 0;
return ret;
}
};
struct L {
SV a;
};
template<class T>
struct Allocation {
T *vec;
void init(T s) {
*vec = s;
}
};
void bar(Allocation<L> a, double g) {
L s = { SV::make() };
a.init(s);
}
produces:
bar(Allocation<L>, double): # @bar(Allocation<L>, double)
sub rsp, 344
xorps xmm0, xmm0
movaps xmmword ptr [rsp], xmm0
mov rsi, rsp
mov edx, 336
call memcpy
add rsp, 344
ret
Moving the capacity field from the beginning of the struct to the end gives the
more desirable:
bar(Allocation<L>, double): # @bar(Allocation<L>, double)
mov qword ptr [rdi], 0
mov qword ptr [rdi + 328], 0
retf
--
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/20181129/3ede0120/attachment.html>
More information about the llvm-bugs
mailing list