[llvm-bugs] [Bug 31572] New: Failure to vectorize mixture of integer multiplies and shift lefts

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jan 7 08:35:05 PST 2017


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: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: a.bataev at hotmail.com, andrew.v.tischenko at gmail.com,
                    llvm-bugs at lists.llvm.org, mkuper at google.com,
                    spatel+llvm at rotateright.com
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170107/81b71afc/attachment-0001.html>


More information about the llvm-bugs mailing list