[clang] [X86] Change target of __builtin_ia32_cmp[p|s][s|d] from avx into sse/sse2 (PR #67410)

Freddy Ye via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 26 05:52:57 PDT 2023


================
@@ -4742,6 +4742,125 @@ static __inline__ __m128d __DEFAULT_FN_ATTRS _mm_castsi128_pd(__m128i __a) {
   return (__m128d)__a;
 }
 
+/// Compares each of the corresponding double-precision values of two
+///    128-bit vectors of [2 x double], using the operation specified by the
+///    immediate integer operand.
+///
+///    Returns a [2 x double] vector consisting of two doubles corresponding to
+///    the two comparison results: zero if the comparison is false, and all 1's
+///    if the comparison is true.
+///
+/// \headerfile <x86intrin.h>
+///
+/// \code
+/// __m128d _mm_cmp_pd(__m128d a, __m128d b, const int c);
+/// \endcode
+///
+/// This intrinsic corresponds to the <c> VCMPPD </c> instruction.
+///
+/// \param a
+///    A 128-bit vector of [2 x double].
+/// \param b
+///    A 128-bit vector of [2 x double].
+/// \param c
+///    An immediate integer operand, with bits [4:0] specifying which comparison
----------------
FreddyLeaf wrote:

After this PR, I'll get such results:
```
$ cat small.c 

#include <immintrin.h>

__m128d cmp (__m128d a, __m128d b)
{
      return _mm_cmp_sd (a, b, 10);
}

$ clang -msse2 -O2 small.c -S -o - | grep cmpsd
        cmpsd   $10, %xmm1, %xmm0
$ clang -mavx -O2 small.c -S -o - | grep vcmp
        vcmpngtsd       %xmm1, %xmm0, %xmm0
```
Not sure if the higher bits could be omitted in encoding. More investigations need to be done. Will update.

https://github.com/llvm/llvm-project/pull/67410


More information about the cfe-commits mailing list