<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 - Suboptimal SLP vectorization"
href="https://bugs.llvm.org/show_bug.cgi?id=50555">50555</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Suboptimal SLP vectorization
</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>Scalar Optimizations
</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>#define N 16
void f (unsigned short *restrict a, unsigned char *restrict b,
unsigned char *restrict c)
{
for (int i = 0; i < N; ++i)
{
unsigned short res = b[i] + c[i];
a[i] = (res + (res >> 1)) >> 2;
}
}
<a href="https://godbolt.org/z/1x8hPbo8d">https://godbolt.org/z/1x8hPbo8d</a>
LLVM -O3 -mavx:
f: # @f
vpmovzxbd xmm0, dword ptr [rsi + 4] # xmm0 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpmovzxbd xmm1, dword ptr [rsi] # xmm1 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpmovzxbd xmm2, dword ptr [rdx + 4] # xmm2 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpmovzxbd xmm3, dword ptr [rdx] # xmm3 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpaddd xmm0, xmm2, xmm0
vpaddd xmm1, xmm3, xmm1
vpsrld xmm2, xmm0, 1
vpsrld xmm3, xmm1, 1
vpaddd xmm1, xmm3, xmm1
vpaddd xmm0, xmm2, xmm0
vpsrld xmm0, xmm0, 2
vpsrld xmm1, xmm1, 2
vpackusdw xmm0, xmm1, xmm0
vmovdqu xmmword ptr [rdi], xmm0
vpmovzxbd xmm0, dword ptr [rsi + 12] # xmm0 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpmovzxbd xmm1, dword ptr [rsi + 8] # xmm1 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpmovzxbd xmm2, dword ptr [rdx + 12] # xmm2 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpaddd xmm0, xmm2, xmm0
vpmovzxbd xmm2, dword ptr [rdx + 8] # xmm2 =
mem[0],zero,zero,zero,mem[1],zero,zero,zero,mem[2],zero,zero,zero,mem[3],zero,zero,zero
vpaddd xmm1, xmm2, xmm1
vpsrld xmm2, xmm0, 1
vpsrld xmm3, xmm1, 1
vpaddd xmm1, xmm3, xmm1
vpaddd xmm0, xmm2, xmm0
vpsrld xmm0, xmm0, 2
vpsrld xmm1, xmm1, 2
vpackusdw xmm0, xmm1, xmm0
vmovdqu xmmword ptr [rdi + 16], xmm0
ret
GCC -O3 -mavx:
f:
vmovdqu xmm1, XMMWORD PTR [rsi]
vmovdqu xmm0, XMMWORD PTR [rdx]
vpmovzxbw xmm3, xmm1
vpsrldq xmm1, xmm1, 8
vpmovzxbw xmm2, xmm0
vpsrldq xmm0, xmm0, 8
vpaddw xmm2, xmm2, xmm3
vpmovzxbw xmm1, xmm1
vpmovzxbw xmm0, xmm0
vpaddw xmm0, xmm0, xmm1
vpsrlw xmm1, xmm2, 1
vpaddw xmm1, xmm1, xmm2
vpsrlw xmm1, xmm1, 2
vmovdqu XMMWORD PTR [rdi], xmm1
vpsrlw xmm1, xmm0, 1
vpaddw xmm0, xmm1, xmm0
vpsrlw xmm0, xmm0, 2
vmovdqu XMMWORD PTR [rdi+16], xmm0
ret
Plain -O3 codegen is suboptimal too. AVX512 codegen looks good.</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>