[llvm-bugs] [Bug 50555] New: Suboptimal SLP vectorization
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Jun 2 00:32:41 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=50555
Bug ID: 50555
Summary: Suboptimal SLP vectorization
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
#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;
}
}
https://godbolt.org/z/1x8hPbo8d
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.
--
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/20210602/a41efe11/attachment-0001.html>
More information about the llvm-bugs
mailing list