<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Worse zero struct init with = T{} than with memset"
href="https://bugs.llvm.org/show_bug.cgi?id=47068">47068</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Worse zero struct init with = T{} than with memset
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>class pt {
int x;
int y;
};
class pt2 {
int x;
char y;
};
void foo(pt* s) {
*s = {};
}
void bar(pt2* s) {
*s = {};
}
For foo case, codegen is fine. The padding is problematic here.
Clang:
ret
bar(pt2*):
mov DWORD PTR [rdi], 0
mov BYTE PTR [rdi+4], 0
ret
ICC:
bar(pt2*):
xor eax, eax #18.4
mov QWORD PTR [rdi], rax #18.8
ret
So ideally we should have:
mov QWORD PTR [rdi], 0
define dso_local void @_Z3fooP2pt(%class.pt* nocapture %0) local_unnamed_addr
#0 {
%2 = bitcast %class.pt* %0 to i64*
store i64 0, i64* %2, align 4
ret void
}
define dso_local void @_Z3barP3pt2(%class.pt2* nocapture %0) local_unnamed_addr
#1 {
%2 = bitcast %class.pt2* %0 to i40*
store i40 0, i40* %2, align 4, !tbaa.struct !2
ret void
}
Looking at dumps, SROA to blame?
--------------------------------------------------
With
class pt3 {
int x;
int y;
char z;
};
Unoptimized:
define dso_local void @_Z3bazP3pt3(%class.pt3* %0) #0 {
%2 = alloca %class.pt3*, align 8
%3 = alloca %class.pt3, align 4
store %class.pt3* %0, %class.pt3** %2, align 8
%4 = bitcast %class.pt3* %3 to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %4, i8 0, i64 12, i1 false)
%5 = load %class.pt3*, %class.pt3** %2, align 8
%6 = bitcast %class.pt3* %5 to i8*
%7 = bitcast %class.pt3* %3 to i8*
call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %6, i8* align 4 %7, i64 9,
i1 false)
ret void
}
Optimized:
define dso_local void @_Z3bazP3pt3(%class.pt3* nocapture %0) local_unnamed_addr
#2 {
%2 = bitcast %class.pt3* %0 to i8*
call void @llvm.memset.p0i8.i64(i8* nonnull align 4 dereferenceable(9) %2, i8
0, i64 9, i1 false)
ret void
}
In this case, we are doing bad job when combing memset and memcpy in
MemCpyOptimizer. It should be:
call void @llvm.memset.p0i8.i64(i8* nonnull align 4 dereferenceable(12) %2, i8
0, i64 12, i1 false)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>