<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 - [X86] IR shufflevector instructions with undef values lowered to sub-optimal sequences"
href="https://bugs.llvm.org/show_bug.cgi?id=34041">34041</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[X86] IR shufflevector instructions with undef values lowered to sub-optimal sequences
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ayman.musa@intel.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>shufflevector IR instruction gets lowered to sub-optimal sequences when its
mask includes undef values.
Small reproducers:
define <4 x double> @foo1(double* %p) {
%s = load double, double* %p
%vec = insertelement <2 x double> undef, double %s, i32 0
%res = shufflevector <2 x double> %vec, <2 x double> undef, <4 x i32> <i32
1, i32 0, i32 0, i32 0>
ret <4 x double> %res
}
Clang emits vmovsd + vpermpd instructions:
vmovsd (%rdi), %xmm0 # xmm0 = mem[0],zero
vpermpd $1, %ymm0, %ymm0 # ymm0 = ymm0[1,0,0,0]
retq
while it can be replaced with simple vbroadcastsd instruction with better
throughput:
vbroadcastsd (%rdi), %ymm0
define <4 x double> @foo2(<2 x double>* %vp, <4 x double> %default) {
%vec = load <2 x double>, <2 x double>* %vp
%shuf = shufflevector <2 x double> %vec, <2 x double> undef, <4 x i32> <i32
0, i32 3, i32 undef, i32 1>
%res = select <4 x i1> <i1 0, i1 1, i1 0, i1 1>, <4 x double> %shuf, <4 x
double> %default
ret <4 x double> %res
}
Clang emits:
vmovapd (%rdi), %xmm1
movb $10, %al
kmovd %eax, %k1
vpermpd $100, %ymm1, %ymm0 {%k1} # ymm0 {%k1} = ymm1[0,1,2,1]
retq
While it can be replaced with:
movb $10, %al
kmovd %eax, %k1
vbroadcastf64x2 (%rdi), %ymm0 {%k1}
define <8 x float> @foo3(<2 x float>* %vp, <8 x float> %default) {
%vec = load <2 x float>, <2 x float>* %vp
%shuf = shufflevector <2 x float> %vec, <2 x float> undef, <8 x i32> <i32
undef, i32 1, i32 undef, i32 undef, i32 0, i32 2, i32 3, i32 undef>
%res = select <8 x i1> <i1 1, i1 1, i1 1, i1 1, i1 1, i1 1, i1 0, i1 1>, <8
x float> %shuf, <8 x float> %default
ret <8 x float> %res
}
clang emits:
vmovsd (%rdi), %xmm1 # xmm1 = mem[0],zero
vbroadcastsd %xmm1, %ymm1
movb $-65, %al
kmovd %eax, %k1
vmovaps %ymm1, %ymm0 {%k1}
retq
While it can combine the mask with a 64-bit broadcast with 32-bit mask
granularity:
movb $-65, %al
kmovd %eax, %k1
vbroadcastf32x2 (%rdi), %ymm1 {%k1}
vmovaps %ymm1, %ymm0
define <8 x double> @foo4(<2 x double>* %vp) {
%vec = load <2 x double>, <2 x double>* %vp
%res = shufflevector <2 x double> %vec, <2 x double> undef, <8 x i32> <i32 3,
i32 1, i32 undef, i32 1, i32 0, i32 1, i32 0, i32 1>
ret <8 x double> %res
}
Clang does not recognize the broadcast template in the mask and emits a shuffle
instruction:
vmovapd (%rdi), %xmm0
vshuff64x2 $0, %zmm0, %zmm0, %zmm0 # zmm0 = zmm0[0,1,0,1,0,1,0,1]
retq
While it can make use of a broadcast instruction which has better throughput
than shuffle:
vbroadcastf64x2 (%rdi), %zmm0
define <8 x double> @foo5(<2 x double>* %vp) {
; CHECK-LABEL: test_2xdouble_to_8xdouble_mem_mask11:
; CHECK: # BB#0:
; CHECK-NEXT: vmovapd (%rdi), %xmm0
; CHECK-NEXT: vinsertf128 $1, %xmm0, %ymm0, %ymm1
; CHECK-NEXT: vinsertf64x4 $1, %ymm1, %zmm0, %zmm0
; CHECK-NEXT: retq
%vec = load <2 x double>, <2 x double>* %vp
%res = shufflevector <2 x double> %vec, <2 x double> undef, <8 x i32> <i32 0,
i32 undef, i32 undef, i32 undef, i32 0, i32 1, i32 0, i32 1>
ret <8 x double> %res
}
Clang emits:
vmovapd (%rdi), %xmm0
vinsertf128 $1, %xmm0, %ymm0, %ymm1
vinsertf64x4 $1, %ymm1, %zmm0, %zmm0
retq
While it can use the broadcast also here:
vbroadcastf64x2 (%rdi), %zmm0</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>