[llvm-bugs] [Bug 33426] New: widening of atomic loads

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Jun 12 13:09:37 PDT 2017


            Bug ID: 33426
           Summary: widening of atomic loads
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org


#include <atomic>
#include <cstring>
#include <x86intrin.h>

alignas(16) std::atomic<char> data[16];

void store(int n, char v) { data[n].store(std::memory_order_relaxed); }

__m128i load() {
  char copy[16];
  for (int n = 0; n != 16; ++n)
    copy[n] = data[n].load(std::memory_order_relaxed);
  __m128i result;
  std::memcpy(&result, copy, 16);
  return result;

When targeting x86_64, LLVM optimizes the 'load' function to a sequence of 16
load/store pairs:

        movb    data(%rip), %al
        movb    %al, -24(%rsp)
        movb    data+1(%rip), %al
        movb    %al, -23(%rsp)
        movb    data+2(%rip), %al
        movb    %al, -22(%rsp)
        movb    data+3(%rip), %al
        movb    %al, -21(%rsp)
        movb    data+4(%rip), %al
        movb    %al, -20(%rsp)
        movb    data+5(%rip), %al
        movb    %al, -19(%rsp)
        movb    data+6(%rip), %al
        movb    %al, -18(%rsp)
        movb    data+7(%rip), %al
        movb    %al, -17(%rsp)
        movb    data+8(%rip), %al
        movb    %al, -16(%rsp)
        movb    data+9(%rip), %al
        movb    %al, -15(%rsp)
        movb    data+10(%rip), %al
        movb    %al, -14(%rsp)
        movb    data+11(%rip), %al
        movb    %al, -13(%rsp)
        movb    data+12(%rip), %al
        movb    %al, -12(%rsp)
        movb    data+13(%rip), %al
        movb    %al, -11(%rsp)
        movb    data+14(%rip), %al
        movb    %al, -10(%rsp)
        movb    data+15(%rip), %al
        movb    %al, -9(%rsp)
        movaps  -24(%rsp), %xmm0

The function should be optimized to a single 16-byte load.

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/20170612/3b968dbd/attachment.html>

More information about the llvm-bugs mailing list