[llvm-bugs] [Bug 34219] New: SLP vectorizer: aligned store to unaligned address

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Aug 17 03:01:34 PDT 2017


            Bug ID: 34219
           Summary: SLP vectorizer: aligned store to unaligned address
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: vsna7ma4he at jorrit.de
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The reproducer causes clang++ to generate a movdqa instruction to an address
that is not sufficiently aligned, causing a SEGFAULT on x86-64.  This happens
with -O2, but not with -O2 -fno-slp-vectorize.  This was originally observed

  clang version 3.8.0 (tags/RELEASE_380/final 263969)

it can still be seen in the assembler output of what godbolt calls clang trunk

  clang version 6.0.0 (trunk 310993)

The offending instruction is this store -- movdqa requires alignment to 16
bytes, but the address is only aligned to 8 bytes.

  movdqa %xmm0,0x200b3d(%rip) # 601058 <counters+0x8>

// compile with:
// clang++ -std=c++14 -O2 -Wall -g -pedantic -pthread reproducer.cpp
long m = 3;
struct alignas(16) Counters {
  long padding;
  long c0;
  long c1;
} counters;
int main() {
  ++counters.c0; ++counters.c1;

  if(m & 1) { ++counters.c0; ++counters.c1; }
  if(m & 2) { ++counters.c0; ++counters.c1; }

Disassmbly (clang trunk from godbolt).  The offending instruction is the
fourth from the bottom.
 jmpq *0x200c12(%rip) # 600ff8 <_DYNAMIC+0x200>
 xchg %ax,%ax
 movdqu 0x200b80(%rip),%xmm1 # 601058 <counters+0x8>
 pcmpeqd %xmm2,%xmm2
 movdqa %xmm1,%xmm0
 psubq %xmm2,%xmm0
 movdqu %xmm0,0x200b6c(%rip) # 601058 <counters+0x8>
 mov 0x200b3d(%rip),%rax # 601030 <m>
 test $0x1,%al
 je 400503 <main+0x33>
 paddq 0xb1(%rip),%xmm1 # 4005b0 <_IO_stdin_used+0x10>
 movdqa %xmm1,%xmm0
 test $0x3,%al
 je 40051b <main+0x4b>
 test $0x2,%al
 je 400513 <main+0x43>
 pcmpeqd %xmm1,%xmm1
 psubq %xmm1,%xmm0
 movdqa %xmm0,0x200b3d(%rip) # 601058 <counters+0x8>
 xor %eax,%eax
 xchg %ax,%ax

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/20170817/f88a1745/attachment.html>

More information about the llvm-bugs mailing list