<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 - Preferred canonicalization - select-of-idx vs select-of-gep ?"
href="https://bugs.llvm.org/show_bug.cgi?id=50183">50183</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Preferred canonicalization - select-of-idx vs select-of-gep ?
</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>Scalar Optimizations
</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>llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>If we're selecting between the base address and base+idx, which is the
preferred canonicalization?
define <4 x i32> @select0(<4 x i32>* %a0, i64 %a1, i1 %a2) {
%gep = getelementptr inbounds <4 x i32>, <4 x i32>* %a0, i64 %a1
%sel = select i1 %a2, <4 x i32>* %a0, <4 x i32>* %gep
%res = load <4 x i32>, <4 x i32>* %sel
ret <4 x i32> %res
}
select0:
shlq $4, %rsi
addq %rdi, %rsi
testb $1, %dl
cmovneq %rdi, %rsi
vmovaps (%rsi), %xmm0
retq
define <4 x i32> @select1(<4 x i32>* %a0, i64 %a1, i1 %a2) {
%sel = select i1 %a2, i64 %a1, i64 0
%gep = getelementptr inbounds <4 x i32>, <4 x i32>* %a0, i64 %sel
%res = load <4 x i32>, <4 x i32>* %gep
ret <4 x i32> %res
}
select1:
xorl %eax, %eax
testb $1, %dl
cmovneq %rsi, %rax
shlq $4, %rax
vmovaps (%rdi,%rax), %xmm0
retq
<a href="https://godbolt.org/z/Yxs3fjbWo">https://godbolt.org/z/Yxs3fjbWo</a>
opt -O3 doesn't seem to have any effect.
X86 could have a slight preference for select1 (select-of-idx) as it moves more
of the address math into the fold, which is useful if the base address has
additional uses (the use case this was pulled from was clamping the
out-of-bounds indices to zero for several of these in an unrolled loop).</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>