[llvm-bugs] [Bug 45794] New: [X86][AVX] Poor sitofp v4i64 to v4f32 conversion
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon May 4 05:03:14 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=45794
Bug ID: 45794
Summary: [X86][AVX] Poor sitofp v4i64 to v4f32 conversion
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: llvm-dev at redking.me.uk
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, spatel+llvm at rotateright.com
Split off from [Bug #39974]:
https://c.godbolt.org/z/-rvyDZ
#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
--
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/20200504/091ae0e5/attachment.html>
More information about the llvm-bugs
mailing list