[llvm-bugs] [Bug 37423] New: Loop vectorizer produces extremely poor code for pattern fills

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 11 12:32:39 PDT 2018


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

            Bug ID: 37423
           Summary: Loop vectorizer produces extremely poor code for
                    pattern fills
           Product: libraries
           Version: 6.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: fabiang at radgametools.com
                CC: llvm-bugs at lists.llvm.org

void patternFill(int *arr, int count)
{
    for (int i = 0; i < count; i++)
        arr[i] = (i & 1) ? 456 : 123;
}

With clang 6.0 release, "clang -O2" on x86-64, this turns into a lot of code,
with the inner loop being

.LBB0_8: # =>This Inner Loop Header: Depth=1
  movdqa %xmm1, %xmm7
  pand %xmm4, %xmm7
  movdqa %xmm2, %xmm0
  pand %xmm4, %xmm0
  pcmpeqd %xmm3, %xmm0
  pshufd $177, %xmm0, %xmm5 # xmm5 = xmm0[1,0,3,2]
  pand %xmm0, %xmm5
  pcmpeqd %xmm3, %xmm7
  pshufd $177, %xmm7, %xmm0 # xmm0 = xmm7[1,0,3,2]
  pand %xmm7, %xmm0
  shufps $136, %xmm0, %xmm5 # xmm5 = xmm5[0,2],xmm0[0,2]
  movaps %xmm5, %xmm0
  andnps %xmm8, %xmm0
  andps %xmm9, %xmm5
  orps %xmm0, %xmm5
  movups %xmm5, (%rdi,%rsi,4)
  movups %xmm5, 16(%rdi,%rsi,4)
  movups %xmm5, 32(%rdi,%rsi,4)
  movups %xmm5, 48(%rdi,%rsi,4)
  addq $16, %rsi
  paddq %xmm6, %xmm2
  paddq %xmm6, %xmm1
  addq $4, %rax
  jne .LBB0_8

by comparison, compiling with "-fno-vectorize" results in the much better (in
terms of both code size and expected execution time)

  movaps .LCPI0_0(%rip), %xmm0 # xmm0 = [123,456,123,456]
.LBB0_8: # =>This Inner Loop Header: Depth=1
  movups %xmm0, (%rdi,%rcx,4)
  addq $4, %rcx
  cmpq %rcx, %rdx
  jne .LBB0_8

-- 
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/20180511/b104a4c8/attachment-0001.html>


More information about the llvm-bugs mailing list