[llvm-bugs] [Bug 47924] New: Better codegen for vector elem set at variable index
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Oct 20 13:42:19 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47924
Bug ID: 47924
Summary: Better codegen for vector elem set at variable index
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, pengfei.wang at intel.com,
spatel+llvm at rotateright.com
#define N 32
typedef int T;
typedef T V __attribute__((vector_size(N)));
V vec_set (V v, int idx, T val)
{
v[idx] = val;
return v;
}
=>
V vec_set_opt (V v, int idx, T val)
{
V valv = (V){idx, idx, idx, idx, idx, idx, idx, idx};
V mask = ((V){0, 1, 2, 3, 4, 5, 6, 7} == valv);
v = (v & ~mask) | (valv & mask);
return v;
}
Clang -O3 -mavx2
vec_set(int __vector(8), int, int): # @vec_set(int
__vector(8), int, int)
push rbp
mov rbp, rsp
and rsp, -32
sub rsp, 64
vmovaps ymmword ptr [rsp], ymm0
and edi, 7
mov dword ptr [rsp + 4*rdi], esi
vmovaps ymm0, ymmword ptr [rsp]
mov rsp, rbp
pop rbp
ret
.LCPI1_0:
.long 0 # 0x0
.long 1 # 0x1
.long 2 # 0x2
.long 3 # 0x3
.long 4 # 0x4
.long 5 # 0x5
.long 6 # 0x6
.long 7 # 0x7
vec_set_opt(int __vector(8), int, int): # @vec_set_opt(int
__vector(8), int, int)
vmovd xmm1, edi
vpbroadcastd ymm1, xmm1
vmovdqa ymm2, ymmword ptr [rip + .LCPI1_0] # ymm2 = [0,1,2,3,4,5,6,7]
vpcmpeqd ymm1, ymm1, ymm2
vblendvps ymm0, ymm0, ymm2, ymm1
ret
https://godbolt.org/z/zvYMzT
--
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/20201020/282aeaa3/attachment.html>
More information about the llvm-bugs
mailing list