<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - [wrong code] _mm_alignr_epi8 is transformed to an incorrect shift" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24187&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=ONbzg9-bQ_zcmcPTir-DJRVxbquHGqvR8w4qqrQMNCw&s=oxrf3JMYxga8wW7dqo7Prc7ll_YRddHpBmvHEbR3P9w&e=">24187</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[wrong code] _mm_alignr_epi8 is transformed to an incorrect shift
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.7
          </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>normal
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>kretz@kde.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following program:
#include <cstdio>
#include <x86intrin.h>

void print(__m128i a)
{
    alignas(16) int m[4];
    _mm_store_si128(reinterpret_cast<__m128i*>(m), a);
    std::printf("[%d %d %d %d]\n", m[0], m[1], m[2], m[3]);
}

int main()
{
    __m128i lo = _mm_setr_epi32(0, 1, 2, 3);
    __m128i hi = _mm_setr_epi32(4, 5, 6, 7);
    print(_mm_alignr_epi8(hi, lo, 0 * 4));
    print(_mm_alignr_epi8(hi, lo, 1 * 4));
    print(_mm_alignr_epi8(hi, lo, 2 * 4));
    print(_mm_alignr_epi8(hi, lo, 3 * 4));
    print(_mm_alignr_epi8(hi, lo, 4 * 4));
    print(_mm_alignr_epi8(hi, lo, 5 * 4));
    print(_mm_alignr_epi8(hi, lo, 6 * 4));
    print(_mm_alignr_epi8(hi, lo, 7 * 4));
    print(_mm_alignr_epi8(hi, lo, 8 * 4));
    return 0;
}

It prints:
[0 1 2 3]
[1 2 3 4]
[2 3 4 5]
[3 4 5 6]
[4 5 6 7]
[1 2 3 0]
[2 3 0 0]
[3 0 0 0]
[0 0 0 0]

It should print:
[0 1 2 3]
[1 2 3 4]
[2 3 4 5]
[3 4 5 6]
[4 5 6 7]
[5 6 7 0]
[6 7 0 0]
[7 0 0 0]
[0 0 0 0]

Reduced testcase:
#include <tmmintrin.h>

int main()
{   
    alignas(16) int m[4];
    *reinterpret_cast<__m128i*>(m) = _mm_alignr_epi8((__v4si{4, 5, 6, 7}),
                                                     (__v4si{0, 1, 2, 3}), 20);
    if (m[0] != 5) {
        abort();
    }
    return 0;
}</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>