| 1 |
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fclangir -emit-cir -o %t.cir -Wall -Werror |
| 2 |
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s |
| 3 |
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fno-signed-char -fclangir -emit-cir -o %t.cir -Wall -Werror |
| 4 |
// RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s |
| 5 |
|
| 6 |
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fclangir -emit-llvm -o %t.ll -Wall -Werror |
| 7 |
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s |
| 8 |
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +sse2 -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror |
| 9 |
// RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s |
| 10 |
|
| 11 |
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG |
| 12 |
// RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG |
| 13 |
|
| 14 |
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG |
| 15 |
// RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +sse2 -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG |
| 16 |
|
| 17 |
// This test mimics clang/test/CodeGen/X86/sse2-builtins.c, which eventually |
| 18 |
// CIR shall be able to support fully. |
| 19 |
|
| 20 |
#include <immintrin.h> |
| 21 |
|
| 22 |
__m128d test_mm_undefined_pd(void) { |
| 23 |
// CIR-LABEL: _mm_undefined_pd |
| 24 |
// CIR: %{{.*}} = cir.const #cir.zero : !cir.vector<2 x !cir.double> |
| 25 |
// CIR: cir.return %{{.*}} : !cir.vector<2 x !cir.double> |
| 26 |
|
| 27 |
// CIR-LABEL: cir.func {{.*}}test_mm_undefined_pd |
| 28 |
// CIR: call @_mm_undefined_pd |
| 29 |
|
| 30 |
// LLVM-LABEL: test_mm_undefined_pd |
| 31 |
// LLVM: store <2 x double> zeroinitializer, ptr %[[A:.*]], align 16 |
| 32 |
// LLVM: %{{.*}} = load <2 x double>, ptr %[[A]], align 16 |
| 33 |
// LLVM: ret <2 x double> %{{.*}} |
| 34 |
|
| 35 |
// OGCG-LABEL: test_mm_undefined_pd |
| 36 |
// OGCG: ret <2 x double> zeroinitializer |
| 37 |
return _mm_undefined_pd(); |
| 38 |
} |
| 39 |
|
| 40 |
__m128i test_mm_undefined_si128(void) { |
| 41 |
// CIR-LABEL: _mm_undefined_si128 |
| 42 |
// CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<2 x !cir.double> |
| 43 |
// CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<2 x !cir.double> -> |
| 44 |
// CIR: cir.return %{{.*}} : |
| 45 |
|
| 46 |
// CIR-LABEL: cir.func {{.*}}test_mm_undefined_si128 |
| 47 |
// CIR: call @_mm_undefined_si128 |
| 48 |
|
| 49 |
// LLVM-LABEL: test_mm_undefined_si128 |
| 50 |
// LLVM: store <2 x i64> zeroinitializer, ptr %[[A:.*]], align 16 |
| 51 |
// LLVM: %{{.*}} = load <2 x i64>, ptr %[[A]], align 16 |
| 52 |
// LLVM: ret <2 x i64> %{{.*}} |
| 53 |
|
| 54 |
// OGCG-LABEL: test_mm_undefined_si128 |
| 55 |
// OGCG: ret <2 x i64> zeroinitializer |
| 56 |
return _mm_undefined_si128(); |
| 57 |
} |
| 58 |
|
| 59 |
// Lowering to pextrw requires optimization. |
| 60 |
int test_mm_extract_epi16(__m128i A) { |
| 61 |
// CIR-LABEL: test_mm_extract_epi16 |
| 62 |
// CIR %{{.*}} = cir.vec.extract %{{.*}}[%{{.*}} : {{!u32i|!u64i}}] : !cir.vector<!s16i x 8> |
| 63 |
// CIR %{{.*}} = cir.cast integral %{{.*}} : !u16i -> !s32i |
| 64 |
|
| 65 |
// LLVM-LABEL: test_mm_extract_epi16 |
| 66 |
// LLVM: extractelement <8 x i16> %{{.*}}, {{i32|i64}} 1 |
| 67 |
// LLVM: zext i16 %{{.*}} to i32 |
| 68 |
|
| 69 |
// OGCG-LABEL: test_mm_extract_epi16 |
| 70 |
// OGCG: extractelement <8 x i16> %{{.*}}, {{i32|i64}} 1 |
| 71 |
// OGCG: zext i16 %{{.*}} to i32 |
| 72 |
return _mm_extract_epi16(A, 1); |
| 73 |
} |
| 74 |
|
| 75 |
void test_mm_clflush(void* A) { |
| 76 |
// CIR-LABEL: test_mm_clflush |
| 77 |
// LLVM-LABEL: test_mm_clflush |
| 78 |
// OGCG-LABEL: test_mm_clflush |
| 79 |
_mm_clflush(A); |
| 80 |
// CIR: {{%.*}} = cir.call_llvm_intrinsic "x86.sse2.clflush" {{%.*}} : (!cir.ptr<!void>) -> !void |
| 81 |
// LLVM: call void @llvm.x86.sse2.clflush(ptr {{%.*}}) |
| 82 |
// OGCG: call void @llvm.x86.sse2.clflush(ptr {{%.*}}) |
| 83 |
} |
| 84 |
|
| 85 |
void test_mm_lfence(void) { |
| 86 |
// CIR-LABEL: test_mm_lfence |
| 87 |
// LLVM-LABEL: test_mm_lfence |
| 88 |
// OGCG-LABEL: test_mm_lfence |
| 89 |
_mm_lfence(); |
| 90 |
// CIR: {{%.*}} = cir.call_llvm_intrinsic "x86.sse2.lfence" : () -> !void |
| 91 |
// LLVM: call void @llvm.x86.sse2.lfence() |
| 92 |
// OGCG: call void @llvm.x86.sse2.lfence() |
| 93 |
} |
| 94 |
|
| 95 |
void test_mm_mfence(void) { |
| 96 |
// CIR-LABEL: test_mm_mfence |
| 97 |
// LLVM-LABEL: test_mm_mfence |
| 98 |
// OGCG-LABEL: test_mm_mfence |
| 99 |
_mm_mfence(); |
| 100 |
// CIR: {{%.*}} = cir.call_llvm_intrinsic "x86.sse2.mfence" : () -> !void |
| 101 |
// LLVM: call void @llvm.x86.sse2.mfence() |
| 102 |
// OGCG: call void @llvm.x86.sse2.mfence() |
| 103 |
} |
| 104 |
|
| 105 |
void test_mm_pause(void) { |
| 106 |
// CIR-LABEL: test_mm_pause |
| 107 |
// LLVM-LABEL: test_mm_pause |
| 108 |
// OGCG-LABEL: test_mm_pause |
| 109 |
_mm_pause(); |
| 110 |
// CIR: {{%.*}} = cir.call_llvm_intrinsic "x86.sse2.pause" : () -> !void |
| 111 |
// LLVM: call void @llvm.x86.sse2.pause() |
| 112 |
// OGCG: call void @llvm.x86.sse2.pause() |
| 113 |
} |
| 114 |
|
| 115 |
__m128i test_mm_shufflelo_epi16(__m128i A) { |
| 116 |
// CIR-LABEL: _mm_shufflelo_epi16 |
| 117 |
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<8 x !s16i>) [#cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i] : !cir.vector<8 x !s16i> |
| 118 |
|
| 119 |
// LLVM-LABEL: test_mm_shufflelo_epi16 |
| 120 |
// LLVM: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 4, i32 5, i32 6, i32 7> |
| 121 |
|
| 122 |
// OGCG-LABEL: test_mm_shufflelo_epi16 |
| 123 |
// OGCG: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 0, i32 0, i32 0, i32 4, i32 5, i32 6, i32 7> |
| 124 |
return _mm_shufflelo_epi16(A, 0); |
| 125 |
} |
| 126 |
|
| 127 |
__m128i test_mm_shufflehi_epi16(__m128i A) { |
| 128 |
// CIR-LABEL: _mm_shufflehi_epi16 |
| 129 |
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<8 x !s16i>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i] : !cir.vector<8 x !s16i> |
| 130 |
|
| 131 |
// LLVM-LABEL: test_mm_shufflehi_epi16 |
| 132 |
// LLVM: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 4, i32 4, i32 4> |
| 133 |
|
| 134 |
// OGCG-LABEL: test_mm_shufflehi_epi16 |
| 135 |
// OGCG: shufflevector <8 x i16> %{{.*}}, <8 x i16> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 4, i32 4, i32 4> |
| 136 |
return _mm_shufflehi_epi16(A, 0); |
| 137 |
} |
| 138 |
|
| 139 |
__m128d test_mm_shuffle_pd(__m128d A, __m128d B) { |
| 140 |
// CIR-LABEL: test_mm_shuffle_pd |
| 141 |
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<2 x !cir.double>) [#cir.int<1> : !s32i, #cir.int<2> : !s32i] : !cir.vector<2 x !cir.double> |
| 142 |
|
| 143 |
// LLVM-LABEL: test_mm_shuffle_pd |
| 144 |
// LLVM: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x i32> <i32 1, i32 2> |
| 145 |
|
| 146 |
// OGCG-LABEL: test_mm_shuffle_pd |
| 147 |
// OGCG: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x i32> <i32 1, i32 2> |
| 148 |
return _mm_shuffle_pd(A, B, 1); |
| 149 |
} |
| 150 |
|
| 151 |
__m128i test_mm_shuffle_epi32(__m128i A) { |
| 152 |
// CIR-LABEL: test_mm_shuffle_epi32 |
| 153 |
// CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}}: !cir.vector<4 x !s32i>) [#cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<0> : !s32i, #cir.int<1> : !s32i] : !cir.vector<4 x !s32i> |
| 154 |
|
| 155 |
// LLVM-LABEL: test_mm_shuffle_epi32 |
| 156 |
// LLVM: shufflevector <4 x i32> %{{.*}}, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1> |
| 157 |
|
| 158 |
// OGCG-LABEL: test_mm_shuffle_epi32 |
| 159 |
// OGCG: shufflevector <4 x i32> %{{.*}}, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1> |
| 160 |
return _mm_shuffle_epi32(A, 0x4E); |
| 161 |
} |
| 162 |
|
| 163 |
__m128i test_mm_mul_epu32(__m128i A, __m128i B) { |
| 164 |
// CIR-LABEL: _mm_mul_epu32 |
| 165 |
// CIR: [[BC_A:%.*]] = cir.cast bitcast %{{.*}} : {{.*}} -> !cir.vector<2 x !s64i> |
| 166 |
// CIR: [[BC_B:%.*]] = cir.cast bitcast %{{.*}} : {{.*}} -> !cir.vector<2 x !s64i> |
| 167 |
// CIR: [[MASK_SCALAR:%.*]] = cir.const #cir.int<4294967295> : !s64i |
| 168 |
// CIR: [[MASK_VEC:%.*]] = cir.vec.splat [[MASK_SCALAR]] : !s64i, !cir.vector<2 x !s64i> |
| 169 |
// CIR: [[AND_A:%.*]] = cir.binop(and, [[BC_A]], [[MASK_VEC]]) |
| 170 |
// CIR: [[AND_B:%.*]] = cir.binop(and, [[BC_B]], [[MASK_VEC]]) |
| 171 |
// CIR: [[MUL:%.*]] = cir.binop(mul, [[AND_A]], [[AND_B]]) |
| 172 |
|
| 173 |
// LLVM-LABEL: _mm_mul_epu32 |
| 174 |
// LLVM: and <2 x i64> %{{.*}}, splat (i64 4294967295) |
| 175 |
// LLVM: and <2 x i64> %{{.*}}, splat (i64 4294967295) |
| 176 |
// LLVM: mul <2 x i64> %{{.*}}, %{{.*}} |
| 177 |
|
| 178 |
// OGCG-LABEL: _mm_mul_epu32 |
| 179 |
// OGCG: and <2 x i64> %{{.*}}, splat (i64 4294967295) |
| 180 |
// OGCG: and <2 x i64> %{{.*}}, splat (i64 4294967295) |
| 181 |
// OGCG: mul <2 x i64> %{{.*}}, %{{.*}} |
| 182 |
|
| 183 |
return _mm_mul_epu32(A, B); |
| 184 |
} |