Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -emit-llvm -o - -Werror | FileCheck %s
      2 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin -target-feature +sse4.1 -fno-signed-char -emit-llvm -o - -Werror | FileCheck %s
      3 
      4 // Don't include mm_malloc.h, it's system specific.
      5 #define __MM_MALLOC_H
      6 
      7 #include <x86intrin.h>
      8 
      9 // NOTE: This should match the tests in llvm/test/CodeGen/X86/sse41-intrinsics-fast-isel.ll
     10 
     11 __m128i test_mm_blend_epi16(__m128i V1, __m128i V2) {
     12   // CHECK-LABEL: test_mm_blend_epi16
     13   // CHECK: shufflevector <8 x i16> %{{.*}}, <8 x i16> %{{.*}}, <8 x i32> <i32 0, i32 9, i32 2, i32 11, i32 4, i32 13, i32 6, i32 7>
     14   return _mm_blend_epi16(V1, V2, 42);
     15 }
     16 
     17 __m128d test_mm_blend_pd(__m128d V1, __m128d V2) {
     18   // CHECK-LABEL: test_mm_blend_pd
     19   // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x i32> <i32 0, i32 3>
     20   return _mm_blend_pd(V1, V2, 2);
     21 }
     22 
     23 __m128 test_mm_blend_ps(__m128 V1, __m128 V2) {
     24   // CHECK-LABEL: test_mm_blend_ps
     25   // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
     26   return _mm_blend_ps(V1, V2, 6);
     27 }
     28 
     29 __m128i test_mm_blendv_epi8(__m128i V1, __m128i V2, __m128i V3) {
     30   // CHECK-LABEL: test_mm_blendv_epi8
     31   // CHECK: call <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}, <16 x i8> %{{.*}})
     32   return _mm_blendv_epi8(V1, V2, V3);
     33 }
     34 
     35 __m128d test_mm_blendv_pd(__m128d V1, __m128d V2, __m128d V3) {
     36   // CHECK-LABEL: test_mm_blendv_pd
     37   // CHECK: call <2 x double> @llvm.x86.sse41.blendvpd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
     38   return _mm_blendv_pd(V1, V2, V3);
     39 }
     40 
     41 __m128 test_mm_blendv_ps(__m128 V1, __m128 V2, __m128 V3) {
     42   // CHECK-LABEL: test_mm_blendv_ps
     43   // CHECK: call <4 x float> @llvm.x86.sse41.blendvps(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
     44   return _mm_blendv_ps(V1, V2, V3);
     45 }
     46 
     47 __m128d test_mm_ceil_pd(__m128d x) {
     48   // CHECK-LABEL: test_mm_ceil_pd
     49   // CHECK: call <2 x double> @llvm.x86.sse41.round.pd(<2 x double> %{{.*}}, i32 2)
     50   return _mm_ceil_pd(x);
     51 }
     52 
     53 __m128 test_mm_ceil_ps(__m128 x) {
     54   // CHECK-LABEL: test_mm_ceil_ps
     55   // CHECK: call <4 x float> @llvm.x86.sse41.round.ps(<4 x float> %{{.*}}, i32 2)
     56   return _mm_ceil_ps(x);
     57 }
     58 
     59 __m128d test_mm_ceil_sd(__m128d x, __m128d y) {
     60   // CHECK-LABEL: test_mm_ceil_sd
     61   // CHECK: call <2 x double> @llvm.x86.sse41.round.sd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 2)
     62   return _mm_ceil_sd(x, y);
     63 }
     64 
     65 __m128 test_mm_ceil_ss(__m128 x, __m128 y) {
     66   // CHECK-LABEL: test_mm_ceil_ss
     67   // CHECK: call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 2)
     68   return _mm_ceil_ss(x, y);
     69 }
     70 
     71 __m128i test_mm_cmpeq_epi64(__m128i A, __m128i B) {
     72   // CHECK-LABEL: test_mm_cmpeq_epi64
     73   // CHECK: icmp eq <2 x i64>
     74   // CHECK: sext <2 x i1> %{{.*}} to <2 x i64>
     75   return _mm_cmpeq_epi64(A, B);
     76 }
     77 
     78 __m128i test_mm_cvtepi8_epi16(__m128i a) {
     79   // CHECK-LABEL: test_mm_cvtepi8_epi16
     80   // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
     81   // CHECK: sext <8 x i8> {{.*}} to <8 x i16>
     82   return _mm_cvtepi8_epi16(a);
     83 }
     84 
     85 __m128i test_mm_cvtepi8_epi32(__m128i a) {
     86   // CHECK-LABEL: test_mm_cvtepi8_epi32
     87   // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
     88   // CHECK: sext <4 x i8> {{.*}} to <4 x i32>
     89   return _mm_cvtepi8_epi32(a);
     90 }
     91 
     92 __m128i test_mm_cvtepi8_epi64(__m128i a) {
     93   // CHECK-LABEL: test_mm_cvtepi8_epi64
     94   // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <2 x i32> <i32 0, i32 1>
     95   // CHECK: sext <2 x i8> {{.*}} to <2 x i64>
     96   return _mm_cvtepi8_epi64(a);
     97 }
     98 
     99 __m128i test_mm_cvtepi16_epi32(__m128i a) {
    100   // CHECK-LABEL: test_mm_cvtepi16_epi32
    101   // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
    102   // CHECK: sext <4 x i16> {{.*}} to <4 x i32>
    103   return _mm_cvtepi16_epi32(a);
    104 }
    105 
    106 __m128i test_mm_cvtepi16_epi64(__m128i a) {
    107   // CHECK-LABEL: test_mm_cvtepi16_epi64
    108   // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <2 x i32> <i32 0, i32 1>
    109   // CHECK: sext <2 x i16> {{.*}} to <2 x i64>
    110   return _mm_cvtepi16_epi64(a);
    111 }
    112 
    113 __m128i test_mm_cvtepi32_epi64(__m128i a) {
    114   // CHECK-LABEL: test_mm_cvtepi32_epi64
    115   // CHECK: shufflevector <4 x i32> {{.*}}, <4 x i32> {{.*}}, <2 x i32> <i32 0, i32 1>
    116   // CHECK: sext <2 x i32> {{.*}} to <2 x i64>
    117   return _mm_cvtepi32_epi64(a);
    118 }
    119 
    120 __m128i test_mm_cvtepu8_epi16(__m128i a) {
    121   // CHECK-LABEL: test_mm_cvtepu8_epi16
    122   // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
    123   // CHECK: zext <8 x i8> {{.*}} to <8 x i16>
    124   return _mm_cvtepu8_epi16(a);
    125 }
    126 
    127 __m128i test_mm_cvtepu8_epi32(__m128i a) {
    128   // CHECK-LABEL: test_mm_cvtepu8_epi32
    129   // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
    130   // CHECK: zext <4 x i8> {{.*}} to <4 x i32>
    131   return _mm_cvtepu8_epi32(a);
    132 }
    133 
    134 __m128i test_mm_cvtepu8_epi64(__m128i a) {
    135   // CHECK-LABEL: test_mm_cvtepu8_epi64
    136   // CHECK: shufflevector <16 x i8> {{.*}}, <16 x i8> {{.*}}, <2 x i32> <i32 0, i32 1>
    137   // CHECK: zext <2 x i8> {{.*}} to <2 x i64>
    138   return _mm_cvtepu8_epi64(a);
    139 }
    140 
    141 __m128i test_mm_cvtepu16_epi32(__m128i a) {
    142   // CHECK-LABEL: test_mm_cvtepu16_epi32
    143   // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
    144   // CHECK: zext <4 x i16> {{.*}} to <4 x i32>
    145   return _mm_cvtepu16_epi32(a);
    146 }
    147 
    148 __m128i test_mm_cvtepu16_epi64(__m128i a) {
    149   // CHECK-LABEL: test_mm_cvtepu16_epi64
    150   // CHECK: shufflevector <8 x i16> {{.*}}, <8 x i16> {{.*}}, <2 x i32> <i32 0, i32 1>
    151   // CHECK: zext <2 x i16> {{.*}} to <2 x i64>
    152   return _mm_cvtepu16_epi64(a);
    153 }
    154 
    155 __m128i test_mm_cvtepu32_epi64(__m128i a) {
    156   // CHECK-LABEL: test_mm_cvtepu32_epi64
    157   // CHECK: shufflevector <4 x i32> {{.*}}, <4 x i32> {{.*}}, <2 x i32> <i32 0, i32 1>
    158   // CHECK: zext <2 x i32> {{.*}} to <2 x i64>
    159   return _mm_cvtepu32_epi64(a);
    160 }
    161 
    162 __m128d test_mm_dp_pd(__m128d x, __m128d y) {
    163   // CHECK-LABEL: test_mm_dp_pd
    164   // CHECK: call <2 x double> @llvm.x86.sse41.dppd(<2 x double> {{.*}}, <2 x double> {{.*}}, i8 7)
    165   return _mm_dp_pd(x, y, 7);
    166 }
    167 
    168 __m128 test_mm_dp_ps(__m128 x, __m128 y) {
    169   // CHECK-LABEL: test_mm_dp_ps
    170   // CHECK: call <4 x float> @llvm.x86.sse41.dpps(<4 x float> {{.*}}, <4 x float> {{.*}}, i8 7)
    171   return _mm_dp_ps(x, y, 7);
    172 }
    173 
    174 int test_mm_extract_epi8(__m128i x) {
    175   // CHECK-LABEL: test_mm_extract_epi8
    176   // CHECK: extractelement <16 x i8> %{{.*}}, i32 1
    177   // CHECK: zext i8 %{{.*}} to i32
    178   return _mm_extract_epi8(x, 1);
    179 }
    180 
    181 int test_mm_extract_epi32(__m128i x) {
    182   // CHECK-LABEL: test_mm_extract_epi32
    183   // CHECK: extractelement <4 x i32> %{{.*}}, i32 1
    184   return _mm_extract_epi32(x, 1);
    185 }
    186 
    187 long long test_mm_extract_epi64(__m128i x) {
    188   // CHECK-LABEL: test_mm_extract_epi64
    189   // CHECK: extractelement <2 x i64> %{{.*}}, i32 1
    190   return _mm_extract_epi64(x, 1);
    191 }
    192 
    193 int test_mm_extract_ps(__m128 x) {
    194   // CHECK-LABEL: test_mm_extract_ps
    195   // CHECK: extractelement <4 x float> %{{.*}}, i32 1
    196   return _mm_extract_ps(x, 1);
    197 }
    198 
    199 __m128d test_mm_floor_pd(__m128d x) {
    200   // CHECK-LABEL: test_mm_floor_pd
    201   // CHECK: call <2 x double> @llvm.x86.sse41.round.pd(<2 x double> %{{.*}}, i32 1)
    202   return _mm_floor_pd(x);
    203 }
    204 
    205 __m128 test_mm_floor_ps(__m128 x) {
    206   // CHECK-LABEL: test_mm_floor_ps
    207   // CHECK: call <4 x float> @llvm.x86.sse41.round.ps(<4 x float> %{{.*}}, i32 1)
    208   return _mm_floor_ps(x);
    209 }
    210 
    211 __m128d test_mm_floor_sd(__m128d x, __m128d y) {
    212   // CHECK-LABEL: test_mm_floor_sd
    213   // CHECK: call <2 x double> @llvm.x86.sse41.round.sd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 1)
    214   return _mm_floor_sd(x, y);
    215 }
    216 
    217 __m128 test_mm_floor_ss(__m128 x, __m128 y) {
    218   // CHECK-LABEL: test_mm_floor_ss
    219   // CHECK: call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 1)
    220   return _mm_floor_ss(x, y);
    221 }
    222 
    223 __m128i test_mm_insert_epi8(__m128i x, char b) {
    224   // CHECK-LABEL: test_mm_insert_epi8
    225   // CHECK: insertelement <16 x i8> %{{.*}}, i8 %{{.*}}, i32 0
    226   return _mm_insert_epi8(x, b, 16);
    227 }
    228 
    229 __m128i test_mm_insert_epi32(__m128i x, int b) {
    230   // CHECK-LABEL: test_mm_insert_epi32
    231   // CHECK: insertelement <4 x i32> %{{.*}}, i32 %{{.*}}, i32 0
    232   return _mm_insert_epi32(x, b, 4);
    233 }
    234 
    235 __m128i test_mm_insert_epi64(__m128i x, long long b) {
    236   // CHECK-LABEL: test_mm_insert_epi64
    237   // CHECK: insertelement <2 x i64> %{{.*}}, i64 %{{.*}}, i32 0
    238   return _mm_insert_epi64(x, b, 2);
    239 }
    240 
    241 __m128 test_mm_insert_ps(__m128 x, __m128 y) {
    242   // CHECK-LABEL: test_mm_insert_ps
    243   // CHECK: call <4 x float> @llvm.x86.sse41.insertps(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i8 4)
    244   return _mm_insert_ps(x, y, 4);
    245 }
    246 
    247 __m128i test_mm_max_epi8(__m128i x, __m128i y) {
    248   // CHECK-LABEL: test_mm_max_epi8
    249   // CHECK:       [[CMP:%.*]] = icmp sgt <16 x i8> [[X:%.*]], [[Y:%.*]]
    250   // CHECK-NEXT:  select <16 x i1> [[CMP]], <16 x i8> [[X]], <16 x i8> [[Y]]
    251   return _mm_max_epi8(x, y);
    252 }
    253 
    254 __m128i test_mm_max_epi32(__m128i x, __m128i y) {
    255   // CHECK-LABEL: test_mm_max_epi32
    256   // CHECK:       [[CMP:%.*]] = icmp sgt <4 x i32> [[X:%.*]], [[Y:%.*]]
    257   // CHECK-NEXT:  select <4 x i1> [[CMP]], <4 x i32> [[X]], <4 x i32> [[Y]]
    258   return _mm_max_epi32(x, y);
    259 }
    260 
    261 __m128i test_mm_max_epu16(__m128i x, __m128i y) {
    262   // CHECK-LABEL: test_mm_max_epu16
    263   // CHECK:       [[CMP:%.*]] = icmp ugt <8 x i16> [[X:%.*]], [[Y:%.*]]
    264   // CHECK-NEXT:  select <8 x i1> [[CMP]], <8 x i16> [[X]], <8 x i16> [[Y]]
    265   return _mm_max_epu16(x, y);
    266 }
    267 
    268 __m128i test_mm_max_epu32(__m128i x, __m128i y) {
    269   // CHECK-LABEL: test_mm_max_epu32
    270   // CHECK:       [[CMP:%.*]] = icmp ugt <4 x i32> [[X:%.*]], [[Y:%.*]]
    271   // CHECK-NEXT:  select <4 x i1> [[CMP]], <4 x i32> [[X]], <4 x i32> [[Y]]
    272   return _mm_max_epu32(x, y);
    273 }
    274 
    275 __m128i test_mm_min_epi8(__m128i x, __m128i y) {
    276   // CHECK-LABEL: test_mm_min_epi8
    277   // CHECK:       [[CMP:%.*]] = icmp slt <16 x i8> [[X:%.*]], [[Y:%.*]]
    278   // CHECK-NEXT:  select <16 x i1> [[CMP]], <16 x i8> [[X]], <16 x i8> [[Y]]
    279   return _mm_min_epi8(x, y);
    280 }
    281 
    282 __m128i test_mm_min_epi32(__m128i x, __m128i y) {
    283   // CHECK-LABEL: test_mm_min_epi32
    284   // CHECK:       [[CMP:%.*]] = icmp slt <4 x i32> [[X:%.*]], [[Y:%.*]]
    285   // CHECK-NEXT:  select <4 x i1> [[CMP]], <4 x i32> [[X]], <4 x i32> [[Y]]
    286   return _mm_min_epi32(x, y);
    287 }
    288 
    289 __m128i test_mm_min_epu16(__m128i x, __m128i y) {
    290   // CHECK-LABEL: test_mm_min_epu16
    291   // CHECK:       [[CMP:%.*]] = icmp ult <8 x i16> [[X:%.*]], [[Y:%.*]]
    292   // CHECK-NEXT:  select <8 x i1> [[CMP]], <8 x i16> [[X]], <8 x i16> [[Y]]
    293   return _mm_min_epu16(x, y);
    294 }
    295 
    296 __m128i test_mm_min_epu32(__m128i x, __m128i y) {
    297   // CHECK-LABEL: test_mm_min_epu32
    298   // CHECK:       [[CMP:%.*]] = icmp ult <4 x i32> [[X:%.*]], [[Y:%.*]]
    299   // CHECK-NEXT:  select <4 x i1> [[CMP]], <4 x i32> [[X]], <4 x i32> [[Y]]
    300   return _mm_min_epu32(x, y);
    301 }
    302 
    303 __m128i test_mm_minpos_epu16(__m128i x) {
    304   // CHECK-LABEL: test_mm_minpos_epu16
    305   // CHECK: call <8 x i16> @llvm.x86.sse41.phminposuw(<8 x i16> %{{.*}})
    306   return _mm_minpos_epu16(x);
    307 }
    308 
    309 __m128i test_mm_mpsadbw_epu8(__m128i x, __m128i y) {
    310   // CHECK-LABEL: test_mm_mpsadbw_epu8
    311   // CHECK: call <8 x i16> @llvm.x86.sse41.mpsadbw(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}, i8 1)
    312   return _mm_mpsadbw_epu8(x, y, 1);
    313 }
    314 
    315 __m128i test_mm_mul_epi32(__m128i x, __m128i y) {
    316   // CHECK-LABEL: test_mm_mul_epi32
    317   // CHECK: call <2 x i64> @llvm.x86.sse41.pmuldq(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
    318   return _mm_mul_epi32(x, y);
    319 }
    320 
    321 __m128i test_mm_mullo_epi32(__m128i x, __m128i y) {
    322   // CHECK-LABEL: test_mm_mullo_epi32
    323   // CHECK: mul <4 x i32>
    324   return _mm_mullo_epi32(x, y);
    325 }
    326 
    327 __m128i test_mm_packus_epi32(__m128i x, __m128i y) {
    328   // CHECK-LABEL: test_mm_packus_epi32
    329   // CHECK: call <8 x i16> @llvm.x86.sse41.packusdw(<4 x i32> %{{.*}}, <4 x i32> %{{.*}})
    330   return _mm_packus_epi32(x, y);
    331 }
    332 
    333 __m128d test_mm_round_pd(__m128d x) {
    334   // CHECK-LABEL: test_mm_round_pd
    335   // CHECK: call <2 x double> @llvm.x86.sse41.round.pd(<2 x double> %{{.*}}, i32 4)
    336   return _mm_round_pd(x, 4);
    337 }
    338 
    339 __m128 test_mm_round_ps(__m128 x) {
    340   // CHECK-LABEL: test_mm_round_ps
    341   // CHECK: call <4 x float> @llvm.x86.sse41.round.ps(<4 x float> %{{.*}}, i32 4)
    342   return _mm_round_ps(x, 4);
    343 }
    344 
    345 __m128d test_mm_round_sd(__m128d x, __m128d y) {
    346   // CHECK-LABEL: test_mm_round_sd
    347   // CHECK: call <2 x double> @llvm.x86.sse41.round.sd(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 4)
    348   return _mm_round_sd(x, y, 4);
    349 }
    350 
    351 __m128 test_mm_round_ss(__m128 x, __m128 y) {
    352   // CHECK-LABEL: test_mm_round_ss
    353   // CHECK: call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 4)
    354   return _mm_round_ss(x, y, 4);
    355 }
    356 
    357 __m128i test_mm_stream_load_si128(__m128i const *a) {
    358   // CHECK-LABEL: test_mm_stream_load_si128
    359   // CHECK: call <2 x i64> @llvm.x86.sse41.movntdqa(i8* %{{.*}})
    360   return _mm_stream_load_si128(a);
    361 }
    362 
    363 int test_mm_test_all_ones(__m128i x) {
    364   // CHECK-LABEL: test_mm_test_all_ones
    365   // CHECK: call i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
    366   return _mm_test_all_ones(x);
    367 }
    368 
    369 int test_mm_test_all_zeros(__m128i x, __m128i y) {
    370   // CHECK-LABEL: test_mm_test_all_zeros
    371   // CHECK: call i32 @llvm.x86.sse41.ptestz(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
    372   return _mm_test_all_zeros(x, y);
    373 }
    374 
    375 int test_mm_test_mix_ones_zeros(__m128i x, __m128i y) {
    376   // CHECK-LABEL: test_mm_test_mix_ones_zeros
    377   // CHECK: call i32 @llvm.x86.sse41.ptestnzc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
    378   return _mm_test_mix_ones_zeros(x, y);
    379 }
    380 
    381 int test_mm_testc_si128(__m128i x, __m128i y) {
    382   // CHECK-LABEL: test_mm_testc_si128
    383   // CHECK: call i32 @llvm.x86.sse41.ptestc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
    384   return _mm_testc_si128(x, y);
    385 }
    386 
    387 int test_mm_testnzc_si128(__m128i x, __m128i y) {
    388   // CHECK-LABEL: test_mm_testnzc_si128
    389   // CHECK: call i32 @llvm.x86.sse41.ptestnzc(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
    390   return _mm_testnzc_si128(x, y);
    391 }
    392 
    393 int test_mm_testz_si128(__m128i x, __m128i y) {
    394   // CHECK-LABEL: test_mm_testz_si128
    395   // CHECK: call i32 @llvm.x86.sse41.ptestz(<2 x i64> %{{.*}}, <2 x i64> %{{.*}})
    396   return _mm_testz_si128(x, y);
    397 }
    398