]> git.ipfire.org Git - thirdparty/gcc.git/commit
i386: Fix up _mm_loadu_si{16,32} [PR99754]
authorJakub Jelinek <jakub@redhat.com>
Mon, 14 Mar 2022 09:44:38 +0000 (10:44 +0100)
committerliuhongt <hongtao.liu@intel.com>
Mon, 28 Mar 2022 01:44:51 +0000 (09:44 +0800)
commit85568e505c3b06708ec0fb21d1ab4f78e0c66896
tree57e6d3a520bb916b3fb88ddc47d4246242d94863
parent6c28ab7adf02d36ee293caba36b37f6c656ed5b0
i386: Fix up _mm_loadu_si{16,32} [PR99754]

These intrinsics are supposed to do an unaligned may_alias load
of a 16-bit or 32-bit value and store it as the first element of
a 128-bit integer vector, with all other elements cleared.

The current _mm_storeu_* implementation implements that correctly, uses
__*_u types to do the store and extracts the first element of a vector into
it.
But _mm_loadu_si{16,32} gets it all wrong.  It performs an aligned
non-may_alias load and because _mm_set_epi{16,32} has the args reversed,
it also inserts it into the last vector element instead of first.

The following patch fixes that.

Note, while the Intrinsics guide for _mm_loadu_si32 says SSE2,
for _mm_loadu_si16 it says strangely SSE.  But the intrinsics
returns __m128i, which is only defined in emmintrin.h, and
_mm_set_epi16 is also only SSE2 and later in emmintrin.h.
Even clang defines it in emmintrin.h and ends up with inlining
failure when calling _mm_loadu_si16 from sse,no-sse2 function.
So, isn't that a bug in the intrinsic guide instead?

2022-03-14  Jakub Jelinek  <jakub@redhat.com>

PR target/99754
* config/i386/emmintrin.h (_mm_loadu_si32): Put loaded value into
first  rather than last element of the vector, use __m32_u to do
a really unaligned load, use just 0 instead of (int)0.
(_mm_loadu_si16): Put loaded value into first rather than last
element of the vector, use __m16_u to do a really unaligned load,
use just 0 instead of (short)0.

* gcc.target/i386/pr99754-1.c: New test.
* gcc.target/i386/pr99754-2.c: New test.
gcc/config/i386/emmintrin.h
gcc/testsuite/gcc.target/i386/pr99754-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/i386/pr99754-2.c [new file with mode: 0644]