<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][AVX] Poor sitofp v4i64 to v4f32 conversion"
href="https://bugs.llvm.org/show_bug.cgi?id=45794">45794</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[X86][AVX] Poor sitofp v4i64 to v4f32 conversion
</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>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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>Split off from [<a class="bz_bug_link
bz_status_CONFIRMED "
title="CONFIRMED - [X86] Vectorize scalar conversions to avoid fpu-gpr-fpu transfers"
href="show_bug.cgi?id=39974">Bug #39974</a>]:
<a href="https://c.godbolt.org/z/-rvyDZ">https://c.godbolt.org/z/-rvyDZ</a>
#include <stdint.h>
#include <x86intrin.h>
__m128 foo128(__m128i x, __m128i y) {
auto xf = __builtin_convertvector(x >> 48, __v2sf);
auto yf = __builtin_convertvector(y >> 48, __v2sf);
return (__v4sf) { xf[0], xf[1], yf[0], yf[1] };
}
__m128 foo256(__m256i x) {
return __builtin_convertvector(x >> 48, __v4sf);
}
-g0 -O3 -march=btver2
define <4 x float> @foo128(<2 x i64> %0, <2 x i64> %1) {
%3 = ashr <2 x i64> %0, <i64 48, i64 48>
%4 = sitofp <2 x i64> %3 to <2 x float>
%5 = ashr <2 x i64> %1, <i64 48, i64 48>
%6 = sitofp <2 x i64> %5 to <2 x float>
%7 = shufflevector <2 x float> %4, <2 x float> %6, <4 x i32> <i32 0, i32 1,
i32 2, i32 3>
ret <4 x float> %7
}
define <4 x float> @foo256(<4 x i64> %0) {
%2 = ashr <4 x i64> %0, <i64 48, i64 48, i64 48, i64 48>
%3 = sitofp <4 x i64> %2 to <4 x float>
ret <4 x float> %3
}
foo128:
vpsrad $16, %xmm0, %xmm0
vpsrad $16, %xmm1, %xmm1
vpshufd $237, %xmm0, %xmm0 # xmm0 = xmm0[1,3,2,3]
vpshufd $237, %xmm1, %xmm1 # xmm1 = xmm1[1,3,2,3]
vcvtdq2ps %xmm0, %xmm0
vcvtdq2ps %xmm1, %xmm1
vmovlhps %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
retq
foo256:
vextractf128 $1, %ymm0, %xmm1
vpsrad $31, %xmm0, %xmm3
vpsrad $16, %xmm0, %xmm0
vpsrad $31, %xmm1, %xmm2
vpsrad $16, %xmm1, %xmm1
vpshufd $245, %xmm0, %xmm0 # xmm0 = xmm0[1,1,3,3]
vpshufd $245, %xmm1, %xmm1 # xmm1 = xmm1[1,1,3,3]
vpblendw $204, %xmm3, %xmm0, %xmm0 # xmm0 =
xmm0[0,1],xmm3[2,3],xmm0[4,5],xmm3[6,7]
vpblendw $204, %xmm2, %xmm1, %xmm1 # xmm1 =
xmm1[0,1],xmm2[2,3],xmm1[4,5],xmm2[6,7]
vpackssdw %xmm1, %xmm0, %xmm0
vcvtdq2ps %xmm0, %xmm0
retq
Neither of these come off well and amazingly for different reasons:
foo128 - missing (in DAG or x86):
shuffle(sitofp(x),sitofp(y)) -> sitofp(shuffle(x,y))
foo256 - all that shuffle code is mostly redundant (vpackss is probably
struggling to count signbits through bitcasts).
In both cases we should get to:
vpsrad $16, %xmm0, %xmm0
vpsrad $16, %xmm1, %xmm1
vshufps ???, %xmm1, %xmm0, %xmm0
vcvtdq2ps %xmm0, %xmm0
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>