[llvm-bugs] [Bug 34041] New: [X86] IR shufflevector instructions with undef values lowered to sub-optimal sequences
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Aug 3 01:14:45 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34041
Bug ID: 34041
Summary: [X86] IR shufflevector instructions with undef values
lowered to sub-optimal sequences
Product: libraries
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: ayman.musa at intel.com
CC: llvm-bugs at lists.llvm.org
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
--
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/20170803/bb43d708/attachment-0001.html>
More information about the llvm-bugs
mailing list