https://llvm.org/bugs/show_bug.cgi?id=31572
Bug ID: 31572
Summary: Failure to vectorize mixture of integer multiplies and
shift lefts
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Scalar Optimizations
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected],
[email protected]
Classification: Unclassified
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
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs