<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - [x86] avoid big bad immediates in the instruction stream, part 3: merge stores"
href="https://llvm.org/bugs/show_bug.cgi?id=24449">24449</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[x86] avoid big bad immediates in the instruction stream, part 3: merge stores
</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>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>This report is based on the post-commit thread for r244601:
<a href="http://reviews.llvm.org/rL244601">http://reviews.llvm.org/rL244601</a>
<a href="http://reviews.llvm.org/D11363">http://reviews.llvm.org/D11363</a>
Sean Silva observed sequences of 11-byte (!) instructions:
20b7f: 48 c7 80 78 01 00 00 00 00 00 00 movq $0, 376(%rax)
20b8a: 48 c7 80 80 01 00 00 00 00 00 00 movq $0, 384(%rax)
20b95: 48 c7 80 88 01 00 00 00 00 00 00 movq $0, 392(%rax)
20ba0: 48 c7 80 90 01 00 00 00 00 00 00 movq $0, 400(%rax)
...
One way to reduce this bloat - merge adjacent stores into a larger store:
vxorps %ymm0, %ymm0, %ymm0 [c5 fc 57 c0]
vmovups %ymm0, 376(%rax) [c5 fc 11 87 78 01 00 00]
...that's 12 bytes instead of 44 (assuming we have AVX for a 32-byte store; if
not, use SSE for 16-byte stores).
It looks like this is a problem in lowering a memset specifically of zeros. If
I change the constant value in the example below, I get the expected store
merging that is implemented in the DAGCombiner:
$ cat memset.c
void big_zero(int *a) {
a[0] = 0;
a[1] = 0;
a[2] = 0;
a[3] = 0;
a[4] = 0;
a[5] = 0;
a[6] = 0;
a[7] = 0;
}
void big_nonzero(int *a) {
a[0] = 1;
a[1] = 1;
a[2] = 1;
a[3] = 1;
a[4] = 1;
a[5] = 1;
a[6] = 1;
a[7] = 1;
}
$ ./clang -O2 -fomit-frame-pointer -mavx memset.c -S -o -
_big_zero
...
movq $0, 24(%rdi)
movq $0, 16(%rdi)
movq $0, 8(%rdi)
movq $0, (%rdi)
retq
_big_nonzero: ## @big_nonzero
...
vmovaps LCPI1_0(%rip), %ymm0 ## ymm0 = [1,1,1,1,1,1,1,1]
vmovups %ymm0, (%rdi)
vzeroupper
retq</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>