[LLVMbugs] [Bug 22753] New: Miscompile explicitly vectorized code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Mar 2 06:08:50 PST 2015


http://llvm.org/bugs/show_bug.cgi?id=22753

            Bug ID: 22753
           Summary: Miscompile explicitly vectorized code
           Product: libraries
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: martin.kronbichler at it.uu.se
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

clang-3.6 miscompiles the following code at -mavx.

$ clang -v
clang version 3.6.0 (tags/RELEASE_360/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation:
$HOME/sw/bin/../lib/gcc/x86_64-linux-gnu/4.9.1
Found candidate GCC installation:
$HOME/sw/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/3.4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.6.3
Selected GCC installation: $HOME/sw/bin/../lib/gcc/x86_64-linux-gnu/4.9.1
Candidate multilib: .;@m64
Selected multilib: .;@m64

-------------------------------------------------

#include <stdio.h>

typedef double __m256d __attribute__((__vector_size__(32)));

class VectorizedArray
{
public:
  VectorizedArray &
  operator += (const VectorizedArray &vec)
  {
    data += vec.data;
    return *this;
  }

  __m256d data;
};

inline
VectorizedArray
operator + (const VectorizedArray &u,
            const VectorizedArray &v)
{
  VectorizedArray tmp = u;
  return tmp+=v;
}


int main()
{
  VectorizedArray a, b, c;
  for (unsigned int i=0; i<4; ++i)
    {
      ((double*)(&a.data))[i] = 2.;
      ((double*)(&b.data))[i] = -1.;
    }
  c = a + b;
  for (unsigned int i=0; i<4; ++i)
    printf("%lf\n", ((const double*)(&c.data))[i]);
}

-------------------------------------------------


$ clang -mavx test.cc && ./a.out
1.000000
1.000000
0.000000
0.000000

(Should be 4 times 1.000000).


The wrong code is in operator+(VectorizedArray const&, VectorizedArray const&):
        vzeroupper
        callq   _ZN15VectorizedArraypLERKS_
        vmovaps (%rax), %ymm0
        vmovaps %ymm0, 64(%rsp)
        vmovupd 64(%rsp), %xmm0
        movq    %rbp, %rsp
        popq    %rbp
        vzeroupper
        retq

Note how the content of %ymm0 gets assigned into an %xmm0 and thus, the upper
128 bits are lost. The code generation is wrong both at -O0 (shown above) and
-O2 and happens for both __m256 and __m256d. clang 3.5 and previous do fine on
this example.

-- 
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/20150302/8bffd871/attachment.html>


More information about the llvm-bugs mailing list