[llvm-bugs] [Bug 34665] New: [AVX] wrong answer after SLP Vectorizer

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Sep 19 04:39:58 PDT 2017


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

            Bug ID: 34665
           Summary: [AVX] wrong answer after SLP Vectorizer
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ilia.taraban at intel.com
                CC: llvm-bugs at lists.llvm.org

This test gives wrong answer after SLP Vectorizer:

================= nice.c ==============
void init (unsigned int a [], unsigned int n)
{
    unsigned int j = 0;
    for (j = 0; j < n; j++) 
        a[j] = (45 + j);
}

int main ()
{
    unsigned int i = 0, k = 0, j = 0, res = 0;
    unsigned int z [64] = {0}, x [64] = {0};
    init((unsigned int * )x, 64);
    scanf(0);
    for (i = 1; i < 6; ++i) 
    {
        for (k = 9; k > 1; --k) 
            x[k] -= k;
        for (j = 2; j < 10; ++j) 
            z[j] = x[j];
    }
    printf("res = %u\n", z[8]);
    return 0;
}
============================================

>>> clang -v
clang version 6.0.0 (trunk 313612)
Target: x86_64-unknown-linux-gnu
Thread model: posix
...

>>> clang -march=skylake -O0 -o nice.exe nice.c
>>> ./nice.exe
res = 13

>>> clang -march=skylake -O2 -o nice.exe nice.c
>>> ./nice.exe
res = 5

If we look at generated asm, we'll see that after SLP vectorization 
storage to ymm2 register is in wrong place, so it result gets an additional
subtraction:
================= nice.s ================== 
...
        callq   scanf
        vmovdqu 8(%rsp), %xmm0         # $rsp = [45, 46, 47, 48, 49, 50, 51,
52, 53, 54, ...]
        vmovdqu 24(%rsp), %xmm1
        vpextrd $3, %xmm1, %r8d
        leal    -9(%r8), %ecx
        movl    %ecx, 36(%rsp)
        vpextrd $2, %xmm1, %r9d
        leal    -8(%r9), %edx
        movl    %edx, 32(%rsp)
        vpextrd $1, %xmm1, %esi
        leal    -7(%rsi), %edx
        movl    %edx, 28(%rsp)
        vpextrd $3, %xmm0, %edi
        leal    -5(%rdi), %edx
        vmovdqu 8(%rsp), %ymm2       # $ymm2 = [47, 48, 49, 50, 51, 45, 45, 45]
...
        vpaddd  .LCPI1_12(%rip), %ymm2, %ymm0          # .LCPI1_12(%rip) =
[-10, -15, -20, -25, -30, -35, -40, -45]
        vmovdqu %ymm0, 8(%rsp)                    # $rsp = [37, 33, 29, 25, 21,
10, 5, 0] - wrong answer 
        vmovups 8(%rsp), %ymm0                     # right answer is [37, 33,
29, 25, 21, 17, 13, 9]
...
===========================================

-- 
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/20170919/9cc52635/attachment.html>


More information about the llvm-bugs mailing list