<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - widening of atomic loads"
   href="https://bugs.llvm.org/show_bug.cgi?id=33426">33426</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>widening of atomic loads
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:

#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
        retq

The function should be optimized to a single 16-byte load.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>