<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 - Pointless loop unroll / vectorization"
href="https://bugs.llvm.org/show_bug.cgi?id=38280">38280</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Pointless loop unroll / vectorization
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>Loop Optimizer
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>fabiang@radgametools.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Example C++ code for x86, simplified from a more complex use case:
// ---- begin
#include <stdint.h>
#include <stddef.h>
#include <emmintrin.h>
// neg_offs <= -8 required
void apply_delta(uint8_t *dst, const uint8_t *src, ptrdiff_t neg_offs, size_t
count)
{
// Just provided for context
while (count >= 8)
{
__m128i src_bytes = _mm_loadl_epi64((const __m128i *) src);
__m128i pred_bytes = _mm_loadl_epi64((const __m128i *) (dst +
neg_offs));
__m128i sum = _mm_add_epi8(src_bytes, pred_bytes);
_mm_storel_epi64((__m128i *) dst, sum);
dst += 8;
src += 8;
count -= 8;
}
// This is the loop in question
while (count--)
{
*dst = *src + dst[neg_offs];
dst++;
src++;
}
}
// ---- end
The bottom (tail) loop gets expanded into a giant monstrosity that attempts to
process 64 bytes at once, with various special-case paths for tail processing,
to handle cases where neg_offs > -64 (which means the obvious
64-elements-at-a-time loop would not work), etc.
The full code can be viewed at <a href="https://godbolt.org/g/yRThcs">https://godbolt.org/g/yRThcs</a>, I won't post it
here. :)
All of which is completely pointless because the tail loop will (as is easy to
see) only ever see count <= 7.
This is an extreme example, but I'm seeing this general pattern (a scalar tail
loop for a manually vectorized loop getting pointlessly auto-vectorized) a lot.</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>