[LLVMbugs] [Bug 24187] New: [wrong code] _mm_alignr_epi8 is transformed to an incorrect shift

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jul 20 03:12:42 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24187

            Bug ID: 24187
           Summary: [wrong code] _mm_alignr_epi8 is transformed to an
                    incorrect shift
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: kretz at kde.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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;
}

-- 
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/20150720/4f50f9b4/attachment.html>


More information about the llvm-bugs mailing list