Debian Codegraph @

clang/test/CIR/CodeGenBuiltins/X86/avx-builtins.c

raw
1 // RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -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 +avx -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 +avx -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 +avx -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-unknown-linux -target-feature +avx -fclangir -emit-cir -o %t.cir -Wall -Werror
12 // RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
13 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fno-signed-char -fclangir -emit-cir -o %t.cir -Wall -Werror
14 // RUN: FileCheck --check-prefixes=CIR --input-file=%t.cir %s
15
16 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fclangir -emit-llvm -o %t.ll -Wall -Werror
17 // RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
18 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx -fno-signed-char -fclangir -emit-llvm -o %t.ll -Wall -Werror
19 // RUN: FileCheck --check-prefixes=LLVM --input-file=%t.ll %s
20
21 // RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
22 // RUN: %clang_cc1 -x c -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
23 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
24 // RUN: %clang_cc1 -x c++ -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=OGCG
25
26 // This test mimics clang/test/CodeGen/X86/avx-builtins.c, which eventually
27 // CIR shall be able to support fully.
28
29 #include <immintrin.h>
30
31 __m256 test_mm256_undefined_ps(void) {
32 // CIR-LABEL: _mm256_undefined_ps
33 // CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.double>
34 // CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<4 x !cir.double> -> !cir.vector<8 x !cir.float>
35 // CIR: cir.return %{{.*}} : !cir.vector<8 x !cir.float>
36
37 // LLVM-LABEL: test_mm256_undefined_ps
38 // LLVM: store <8 x float> zeroinitializer, ptr %[[A:.*]], align 32
39 // LLVM: %{{.*}} = load <8 x float>, ptr %[[A]], align 32
40 // LLVM: ret <8 x float> %{{.*}}
41
42 // OGCG-LABEL: test_mm256_undefined_ps
43 // OGCG: ret <8 x float> zeroinitializer
44 return _mm256_undefined_ps();
45 }
46
47 __m256d test_mm256_undefined_pd(void) {
48 // CIR-LABEL: _mm256_undefined_pd
49 // CIR: %{{.*}} = cir.const #cir.zero : !cir.vector<4 x !cir.double>
50 // CIR: cir.return %{{.*}} : !cir.vector<4 x !cir.double>
51
52 // LLVM-LABEL: test_mm256_undefined_pd
53 // LLVM: store <4 x double> zeroinitializer, ptr %[[A:.*]], align 32
54 // LLVM: %{{.*}} = load <4 x double>, ptr %[[A]], align 32
55 // LLVM: ret <4 x double> %{{.*}}
56
57 // OGCG-LABEL: test_mm256_undefined_pd
58 // OGCG: ret <4 x double> zeroinitializer
59 return _mm256_undefined_pd();
60 }
61
62 __m256i test_mm256_undefined_si256(void) {
63 // CIR-LABEL: _mm256_undefined_si256
64 // CIR: %[[A:.*]] = cir.const #cir.zero : !cir.vector<4 x !cir.double>
65 // CIR: %{{.*}} = cir.cast bitcast %[[A]] : !cir.vector<4 x !cir.double> -> !cir.vector<4 x !s64i>
66 // CIR: cir.return %{{.*}} : !cir.vector<4 x !s64i>
67
68 // LLVM-LABEL: test_mm256_undefined_si256
69 // LLVM: store <4 x i64> zeroinitializer, ptr %[[A:.*]], align 32
70 // LLVM: %{{.*}} = load <4 x i64>, ptr %[[A]], align 32
71 // LLVM: ret <4 x i64> %{{.*}}
72
73 // OGCG-LABEL: test_mm256_undefined_si256
74 // OGCG: ret <4 x i64> zeroinitializer
75 return _mm256_undefined_si256();
76 }
77
78 __m256d test_mm256_insertf128_pd(__m256d A, __m128d B) {
79 // CIR-LABEL: test_mm256_insertf128_pd
80 // %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<2 x !cir.double>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<4 x !cir.double>
81 // %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<4 x !cir.double>) [#cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<4 x !cir.double>
82
83 // LLVM-LABEL: test_mm256_insertf128_pd
84 // LLVM: shufflevector <2 x double> %{{.*}}, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
85 // LLVM: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
86
87 // OGCG-LABEL: test_mm256_insertf128_pd
88 // OGCG: shufflevector <2 x double> %{{.*}}, <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
89 // OGCG: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 4, i32 5, i32 2, i32 3>
90 return _mm256_insertf128_pd(A, B, 0);
91 }
92
93 __m256 test_mm256_insertf128_ps(__m256 A, __m128 B) {
94 // CIR-LABEL: test_mm256_insertf128_ps
95 // %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<4 x !cir.float>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<8 x !cir.float>
96 // %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<8 x !cir.float>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i] : !cir.vector<8 x !cir.float>
97
98 // LLVM-LABEL: test_mm256_insertf128_ps
99 // LLVM: shufflevector <4 x float> %{{.*}}, <4 x float> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
100 // LLVM: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
101
102 // OGCG-LABEL: test_mm256_insertf128_ps
103 // OGCG: shufflevector <4 x float> %{{.*}}, <4 x float> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
104 // OGCG: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 8, i32 9, i32 10, i32 11>
105 return _mm256_insertf128_ps(A, B, 1);
106 }
107
108 __m256i test_mm256_insertf128_si256(__m256i A, __m128i B) {
109 // CIR-LABEL: test_mm256_insertf128_si256
110 // %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<4 x !s32i>) [#cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i] : !cir.vector<8 x !s32i>
111 // %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<8 x !s32i>) [#cir.int<8> : !s32i, #cir.int<9> : !s32i, #cir.int<10> : !s32i, #cir.int<11> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i]
112
113 // LLVM-LABEL: test_mm256_insertf128_si256
114 // LLVM: shufflevector <4 x i32> %{{.*}}, <4 x i32> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
115 // LLVM: shufflevector <8 x i32> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
116
117 // OGCG-LABEL: test_mm256_insertf128_si256
118 // OGCG: shufflevector <4 x i32> %{{.*}}, <4 x i32> poison, <8 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
119 // OGCG: shufflevector <8 x i32> %{{.*}}, <8 x i32> %{{.*}}, <8 x i32> <i32 8, i32 9, i32 10, i32 11, i32 4, i32 5, i32 6, i32 7>
120 return _mm256_insertf128_si256(A, B, 0);
121 }
122
123 __m256d test_mm256_shuffle_pd(__m256d A, __m256d B) {
124 // CIR-LABEL: test_mm256_shuffle_pd
125 // CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<4 x !cir.double>) [#cir.int<0> : !s32i, #cir.int<4> : !s32i, #cir.int<2> : !s32i, #cir.int<6> : !s32i] : !cir.vector<4 x !cir.double>
126
127 // LLVM-LABEL: test_mm256_shuffle_pd
128 // LLVM: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 0, i32 4, i32 2, i32 6>
129
130 // OGCG-LABEL: test_mm256_shuffle_pd
131 // OGCG: shufflevector <4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x i32> <i32 0, i32 4, i32 2, i32 6>
132 return _mm256_shuffle_pd(A, B, 0);
133 }
134
135 __m256 test_mm256_shuffle_ps(__m256 A, __m256 B) {
136 // CIR-LABEL: test_mm256_shuffle_ps
137 // CIR: %{{.*}} = cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<8 x !cir.float>) [#cir.int<0> : !s32i, #cir.int<0> : !s32i, #cir.int<8> : !s32i, #cir.int<8> : !s32i, #cir.int<4> : !s32i, #cir.int<4> : !s32i, #cir.int<12> : !s32i, #cir.int<12> : !s32i] : !cir.vector<8 x !cir.float>
138
139 // LLVM-LABEL: test_mm256_shuffle_ps
140 // LLVM: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 0, i32 8, i32 8, i32 4, i32 4, i32 12, i32 12>
141
142 // OGCG-LABEL: test_mm256_shuffle_ps
143 // OGCG: shufflevector <8 x float> %{{.*}}, <8 x float> %{{.*}}, <8 x i32> <i32 0, i32 0, i32 8, i32 8, i32 4, i32 4, i32 12, i32 12>
144 return _mm256_shuffle_ps(A, B, 0);
145 }
146
147 __m128 test_mm_permute_ps(__m128 A) {
148 // CIR-LABEL: test_mm_permute_ps
149 // CIR: cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<4 x !cir.float>) [#cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<0> : !s32i, #cir.int<1> : !s32i] : !cir.vector<4 x !cir.float>
150
151 // LLVM-LABEL: test_mm_permute_ps
152 // LLVM: shufflevector <4 x float> %{{.*}}, <4 x float> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
153
154 // OGCG-LABEL: test_mm_permute_ps
155 // OGCG: shufflevector <4 x float> %{{.*}}, <4 x float> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
156 return _mm_permute_ps(A, 0x4E);
157 }
158
159 __m256 test_mm256_permute_ps(__m256 A) {
160 // CIR-LABEL: test_mm256_permute_ps
161 // CIR: cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<8 x !cir.float>) [#cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<0> : !s32i, #cir.int<1> : !s32i, #cir.int<6> : !s32i, #cir.int<7> : !s32i, #cir.int<4> : !s32i, #cir.int<5> : !s32i] : !cir.vector<8 x !cir.float>
162
163 // LLVM-LABEL: test_mm256_permute_ps
164 // LLVM: shufflevector <8 x float> %{{.*}}, <8 x float> poison, <8 x i32> <i32 2, i32 3, i32 0, i32 1, i32 6, i32 7, i32 4, i32 5>
165
166 // OGCG-LABEL: test_mm256_permute_ps
167 // OGCG: shufflevector <8 x float> %{{.*}}, <8 x float> poison, <8 x i32> <i32 2, i32 3, i32 0, i32 1, i32 6, i32 7, i32 4, i32 5>
168 return _mm256_permute_ps(A, 0x4E);
169 }
170
171 __m128d test_mm_permute_pd(__m128d A) {
172 // CIR-LABEL: test_mm_permute_pd
173 // CIR: cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<2 x !cir.double>) [#cir.int<1> : !s32i, #cir.int<0> : !s32i] : !cir.vector<2 x !cir.double>
174
175 // LLVM-LABEL: test_mm_permute_pd
176 // LLVM: shufflevector <2 x double> %{{.*}}, <2 x double> poison, <2 x i32> <i32 1, i32 0>
177
178 // OGCG-LABEL: test_mm_permute_pd
179 // OGCG: shufflevector <2 x double> %{{.*}}, <2 x double> poison, <2 x i32> <i32 1, i32 0>
180 return _mm_permute_pd(A, 0x1);
181 }
182
183 __m256d test_mm256_permute_pd(__m256d A) {
184 // CIR-LABEL: test_mm256_permute_pd
185 // CIR: cir.vec.shuffle(%{{.*}}, %{{.*}} : !cir.vector<4 x !cir.double>) [#cir.int<1> : !s32i, #cir.int<0> : !s32i, #cir.int<3> : !s32i, #cir.int<2> : !s32i] : !cir.vector<4 x !cir.double>
186
187 // LLVM-LABEL: test_mm256_permute_pd
188 // LLVM: shufflevector <4 x double> %{{.*}}, <4 x double> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
189
190 // OGCG-LABEL: test_mm256_permute_pd
191 // OGCG: shufflevector <4 x double> %{{.*}}, <4 x double> poison, <4 x i32> <i32 1, i32 0, i32 3, i32 2>
192 return _mm256_permute_pd(A, 0x5);
193 }