<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Failure to vectorize mixture of integer multiplies and shift lefts"
href="https://llvm.org/bugs/show_bug.cgi?id=31572">31572</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Failure to vectorize mixture of integer multiplies and shift lefts
</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>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</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>a.bataev@hotmail.com, andrew.v.tischenko@gmail.com, llvm-bugs@lists.llvm.org, mkuper@google.com, spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>We can vectorize pure integer multiplies quite easily:
void mul_4i32(int * __restrict dst, const int * __restrict src) {
*dst++ = *src++ * 257;
*dst++ = *src++ * -3;
*dst++ = *src++ * -2;
*dst++ = *src++ * -9;
}
mul_4i32:
vmovdqu (%rsi), %xmm0
vpmulld .LCPI0_0(%rip), %xmm0, %xmm0
vmovdqu %xmm0, (%rdi)
retq
But this fails if some of the scalar multiplies can be combined to left shifts
instead:
void mul_as_shift_4i32(int * __restrict dst, const int * __restrict src) {
*dst++ = *src++ * 257;
*dst++ = *src++ * -3;
*dst++ = *src++ * 2;
*dst++ = *src++ * -9;
}
mul_as_shift_4i32:
movl (%rsi), %eax
movl 8(%rsi), %edx
movl %eax, %ecx
addl %edx, %edx
shll $8, %ecx
addl %eax, %ecx
movl %ecx, (%rdi)
imull $-3, 4(%rsi), %ecx
movl %ecx, 4(%rdi)
imull $-9, 12(%rsi), %ecx
movl %edx, 8(%rdi)
movl %ecx, 12(%rdi)
retq
Similarly we should be able to vectorize a mixture of integer multiplies and
left shifts:
void mul_and_shift_4i32(int * __restrict dst, const int * __restrict src) {
*dst++ = *src++ * 257;
*dst++ = *src++ * -3;
*dst++ = *src++ << 4;
*dst++ = *src++ * -9;
}
mul_and_shift_4i32:
movl (%rsi), %eax
movl 8(%rsi), %edx
movl %eax, %ecx
shll $4, %edx
shll $8, %ecx
addl %eax, %ecx
movl %ecx, (%rdi)
imull $-3, 4(%rsi), %ecx
movl %ecx, 4(%rdi)
imull $-9, 12(%rsi), %ecx
movl %edx, 8(%rdi)
movl %ecx, 12(%rdi)
retq</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>