<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 - Better codegen for vector elem set at variable index"
href="https://bugs.llvm.org/show_bug.cgi?id=47924">47924</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Better codegen for vector elem set at variable index
</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>Linux
</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>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>#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
<a href="https://godbolt.org/z/zvYMzT">https://godbolt.org/z/zvYMzT</a></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>