[llvm-bugs] [Bug 28434] New: short fixed count loops are not vectorized without #pragma hints

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 6 05:10:00 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28434

            Bug ID: 28434
           Summary: short fixed count loops are not vectorized without
                    #pragma hints
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nowak-llvm at tepeserwery.pl
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

see https://godbolt.org/g/bLIzA1

void f1(float *__restrict__ q __attribute__((align_value(16))), int
*__restrict__ p __attribute__((align_value(16)))) {
#pragma clang loop unroll(disable)
#pragma clang loop vectorize(enable)
  for (unsigned int i = 0; i < 4; ++i) {
    q[i] = p[i];
  }
}
void f2(float *__restrict__ q __attribute__((align_value(16))), int
*__restrict__ p __attribute__((align_value(16)))) {
#pragma clang loop vectorize(enable)
  for (unsigned int i = 0; i < 4; ++i) {
    q[i] = p[i];
  }
}
void f3(float *__restrict__ q __attribute__((align_value(16))), int
*__restrict__ p __attribute__((align_value(16)))) {
#pragma clang loop unroll(disable)
  for (unsigned int i = 0; i < 4; ++i) {
    q[i] = p[i];
  }
}
void f4(float *__restrict__ q __attribute__((align_value(16))), int
*__restrict__ p __attribute__((align_value(16)))) {
  for (unsigned int i = 0; i < 4; ++i) {
    q[i] = p[i];
  }
}
void f5(float *__restrict__ q __attribute__((align_value(16))), int
*__restrict__ p __attribute__((align_value(16)))) {
  for (unsigned int i = 0; i < 40; ++i) {
    q[i] = p[i];
  }
}

f1 is correctly vectorized when vectorization is forced and loop unrolling
disabled:
        cvtdq2ps        (%rsi), %xmm0
        movaps  %xmm0, (%rdi)

f2 is not correctly vectorized even when vectorization is forced because loop
is fully unrolled before vectorization?:
        cvtsi2ssl       (%rsi), %xmm0
        movss   %xmm0, (%rdi)
        xorps   %xmm0, %xmm0
        cvtsi2ssl       4(%rsi), %xmm0
        movss   %xmm0, 4(%rdi)
        xorps   %xmm0, %xmm0
        ...

f3 is not correctly vectorized when loop unrolling is disabled but
vectorization is not forced:
        xorl    %eax, %eax
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
        xorps   %xmm0, %xmm0
        cvtsi2ssl       (%rsi,%rax,4), %xmm0
        movss   %xmm0, (%rdi,%rax,4)
        incq    %rax
        cmpq    $4, %rax
        jne     .LBB2_1

f4 without any #pragma is not correctly vectorized but is unrolled and produces
same code as f2.

f5 without any #pragma is correctly vectorized and unrolled only when loop
count is ~40 or higher:
        cvtdq2ps        (%rsi), %xmm0
        movaps  %xmm0, (%rdi)
        cvtdq2ps        16(%rsi), %xmm0
        movaps  %xmm0, 16(%rdi)
        ...

-- 
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/20160706/44ceb6fa/attachment-0001.html>


More information about the llvm-bugs mailing list