Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / matrix-casts.cpp
blob4369d99a349158387034bb6a343c0832213105c1
1 // RUN: %clang_cc1 -std=c++11 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
3 template <typename X>
4 using matrix_4_4 = X __attribute__((matrix_type(4, 4)));
6 template <typename Y>
7 using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));
9 // CHECK-LABEL: define{{.*}} void @_Z25CastCharMatrixToIntCStylev()
10 void CastCharMatrixToIntCStyle() {
11 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 1
12 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
13 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
15 matrix_5_5<char> c;
16 matrix_5_5<int> i;
17 i = (matrix_5_5<int>)c;
20 // CHECK-LABEL: define{{.*}} void @_Z29CastCharMatrixToIntStaticCastv()
21 void CastCharMatrixToIntStaticCast() {
22 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 1
23 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
24 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
26 matrix_5_5<char> c;
27 matrix_5_5<int> i;
28 i = static_cast<matrix_5_5<int>>(c);
31 // CHECK-LABEL: define{{.*}} void @_Z33CastCharMatrixToUnsignedIntCStylev
32 void CastCharMatrixToUnsignedIntCStyle() {
33 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 1
34 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
35 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
36 // CHECK-NEXT: ret void
38 matrix_5_5<char> c;
39 matrix_5_5<unsigned int> u;
40 u = (matrix_5_5<unsigned int>)c;
43 // CHECK-LABEL: define{{.*}} void @_Z37CastCharMatrixToUnsignedIntStaticCastv
44 void CastCharMatrixToUnsignedIntStaticCast() {
45 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 1
46 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>
47 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
48 // CHECK-NEXT: ret void
50 matrix_5_5<char> c;
51 matrix_5_5<unsigned int> u;
52 u = static_cast<matrix_5_5<unsigned int>>(c);
55 // CHECK-LABEL: define{{.*}} void @_Z38CastUnsignedLongIntMatrixToShortCStylev
56 void CastUnsignedLongIntMatrixToShortCStyle() {
57 // CHECK: [[U:%.*]] = load <25 x i64>, ptr {{.*}}, align 8
58 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> {{.*}} to <25 x i16>
59 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
60 // CHECK-NEXT: ret void
62 matrix_5_5<unsigned long int> u;
63 matrix_5_5<short int> s;
64 s = (matrix_5_5<short int>)u;
67 // CHECK-LABEL: define{{.*}} void @_Z42CastUnsignedLongIntMatrixToShortStaticCastv
68 void CastUnsignedLongIntMatrixToShortStaticCast() {
69 // CHECK: [[U:%.*]] = load <25 x i64>, ptr {{.*}}, align 8
70 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> {{.*}} to <25 x i16>
71 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
72 // CHECK-NEXT: ret void
74 matrix_5_5<unsigned long int> u;
75 matrix_5_5<short int> s;
76 s = static_cast<matrix_5_5<short int>>(u);
79 // CHECK-LABEL: define{{.*}} void @_Z26CastIntMatrixToShortCStylev()
80 void CastIntMatrixToShortCStyle() {
81 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 4
82 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i32> [[I]] to <25 x i16>
83 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
84 // CHECK-NEXT: ret void
86 matrix_5_5<int> i;
87 matrix_5_5<short int> s;
88 s = (matrix_5_5<short int>)i;
91 // CHECK-LABEL: define{{.*}} void @_Z30CastIntMatrixToShortStaticCastv()
92 void CastIntMatrixToShortStaticCast() {
93 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 4
94 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i32> [[I]] to <25 x i16>
95 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
96 // CHECK-NEXT: ret void
98 matrix_5_5<int> i;
99 matrix_5_5<short int> s;
100 s = static_cast<matrix_5_5<short int>>(i);
103 // CHECK-LABEL: define{{.*}} void @_Z26CastIntMatrixToFloatCStylev()
104 void CastIntMatrixToFloatCStyle() {
105 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 4
106 // CHECK-NEXT: [[CONV]] = sitofp <25 x i32> {{.*}} to <25 x float>
107 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4
108 // CHECK-NEXT: ret void
110 matrix_5_5<int> i;
111 matrix_5_5<float> f;
112 f = (matrix_5_5<float>)i;
115 // CHECK-LABEL: define{{.*}} void @_Z30CastIntMatrixToFloatStaticCastv()
116 void CastIntMatrixToFloatStaticCast() {
117 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 4
118 // CHECK-NEXT: [[CONV]] = sitofp <25 x i32> {{.*}} to <25 x float>
119 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4
120 // CHECK-NEXT: ret void
122 matrix_5_5<int> i;
123 matrix_5_5<float> f;
124 f = static_cast<matrix_5_5<float>>(i);
127 // CHECK-LABEL: define{{.*}} void @_Z34CastUnsignedIntMatrixToFloatCStylev()
128 void CastUnsignedIntMatrixToFloatCStyle() {
129 // CHECK: [[U:%.*]] = load <25 x i16>, ptr {{.*}}, align 2
130 // CHECK-NEXT: [[CONV:%.*]] = uitofp <25 x i16> [[U]] to <25 x float>
131 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4
132 // CHECK-NEXT: ret void
134 matrix_5_5<unsigned short int> u;
135 matrix_5_5<float> f;
136 f = (matrix_5_5<float>)u;
139 // CHECK-LABEL: define{{.*}} void @_Z38CastUnsignedIntMatrixToFloatStaticCastv()
140 void CastUnsignedIntMatrixToFloatStaticCast() {
141 // CHECK: [[U:%.*]] = load <25 x i16>, ptr {{.*}}, align 2
142 // CHECK-NEXT: [[CONV:%.*]] = uitofp <25 x i16> [[U]] to <25 x float>
143 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4
144 // CHECK-NEXT: ret void
146 matrix_5_5<unsigned short int> u;
147 matrix_5_5<float> f;
148 f = static_cast<matrix_5_5<float>>(u);
151 // CHECK-LABEL: define{{.*}} void @_Z27CastDoubleMatrixToIntCStylev()
152 void CastDoubleMatrixToIntCStyle() {
153 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8
154 // CHECK-NEXT: [[CONV:%.*]] = fptosi <25 x double> [[D]] to <25 x i32>
155 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
156 // CHECK-NEXT: ret void
158 matrix_5_5<double> d;
159 matrix_5_5<int> i;
160 i = (matrix_5_5<int>)d;
163 // CHECK-LABEL: define{{.*}} void @_Z31CastDoubleMatrixToIntStaticCastv()
164 void CastDoubleMatrixToIntStaticCast() {
165 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8
166 // CHECK-NEXT: [[CONV:%.*]] = fptosi <25 x double> [[D]] to <25 x i32>
167 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
168 // CHECK-NEXT: ret void
170 matrix_5_5<double> d;
171 matrix_5_5<int> i;
172 i = static_cast<matrix_5_5<int>>(d);
175 // CHECK-LABEL: define{{.*}} void @_Z39CastFloatMatrixToUnsignedShortIntCStylev()
176 void CastFloatMatrixToUnsignedShortIntCStyle() {
177 // CHECK: [[F:%.*]] = load <25 x float>, ptr {{.*}}, align 4
178 // CHECK-NEXT: [[CONV:%.*]] = fptoui <25 x float> [[F]] to <25 x i16>
179 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
180 // CHECK-NEXT: ret void
182 matrix_5_5<float> f;
183 matrix_5_5<unsigned short int> i;
184 i = (matrix_5_5<unsigned short int>)f;
187 // CHECK-LABEL: define{{.*}} void @_Z43CastFloatMatrixToUnsignedShortIntStaticCastv()
188 void CastFloatMatrixToUnsignedShortIntStaticCast() {
189 // CHECK: [[F:%.*]] = load <25 x float>, ptr {{.*}}, align 4
190 // CHECK-NEXT: [[CONV:%.*]] = fptoui <25 x float> [[F]] to <25 x i16>
191 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
192 // CHECK-NEXT: ret void
194 matrix_5_5<float> f;
195 matrix_5_5<unsigned short int> i;
196 i = static_cast<matrix_5_5<unsigned short int>>(f);
199 // CHECK-LABEL: define{{.*}} void @_Z29CastDoubleMatrixToFloatCStylev()
200 void CastDoubleMatrixToFloatCStyle() {
201 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8
202 // CHECK-NEXT: [[CONV:%.*]] = fptrunc <25 x double> [[D]] to <25 x float>
203 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4
204 // CHECK-NEXT: ret void
206 matrix_5_5<double> d;
207 matrix_5_5<float> f;
208 f = (matrix_5_5<float>)d;
211 // CHECK-LABEL: define{{.*}} void @_Z33CastDoubleMatrixToFloatStaticCastv()
212 void CastDoubleMatrixToFloatStaticCast() {
213 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8
214 // CHECK-NEXT: [[CONV:%.*]] = fptrunc <25 x double> [[D]] to <25 x float>
215 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4
216 // CHECK-NEXT: ret void
218 matrix_5_5<double> d;
219 matrix_5_5<float> f;
220 f = static_cast<matrix_5_5<float>>(d);
223 // CHECK-LABEL: define{{.*}} void @_Z39CastUnsignedShortIntToUnsignedIntCStylev()
224 void CastUnsignedShortIntToUnsignedIntCStyle() {
225 // CHECK: [[S:%.*]] = load <25 x i16>, ptr {{.*}}, align 2
226 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[S]] to <25 x i32>
227 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
228 // CHECK-NEXT: ret void
230 matrix_5_5<unsigned short int> s;
231 matrix_5_5<unsigned int> i;
232 i = (matrix_5_5<unsigned int>)s;
235 // CHECK-LABEL: define{{.*}} void @_Z43CastUnsignedShortIntToUnsignedIntStaticCastv()
236 void CastUnsignedShortIntToUnsignedIntStaticCast() {
237 // CHECK: [[S:%.*]] = load <25 x i16>, ptr {{.*}}, align 2
238 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[S]] to <25 x i32>
239 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
240 // CHECK-NEXT: ret void
242 matrix_5_5<unsigned short int> s;
243 matrix_5_5<unsigned int> i;
244 i = static_cast<matrix_5_5<unsigned int>>(s);
247 // CHECK-LABEL: define{{.*}} void @_Z43CastUnsignedLongIntToUnsignedShortIntCStylev()
248 void CastUnsignedLongIntToUnsignedShortIntCStyle() {
249 // CHECK: [[L:%.*]] = load <25 x i64>, ptr %l, align 8
250 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> [[L]] to <25 x i16>
251 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
252 // CHECK-NEXT: ret void
254 matrix_5_5<unsigned long int> l;
255 matrix_5_5<unsigned short int> s;
256 s = (matrix_5_5<unsigned short int>)l;
259 // CHECK-LABEL: define{{.*}} void @_Z47CastUnsignedLongIntToUnsignedShortIntStaticCastv()
260 void CastUnsignedLongIntToUnsignedShortIntStaticCast() {
261 // CHECK: [[L:%.*]] = load <25 x i64>, ptr %l, align 8
262 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> [[L]] to <25 x i16>
263 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2
264 // CHECK-NEXT: ret void
266 matrix_5_5<unsigned long int> l;
267 matrix_5_5<unsigned short int> s;
268 s = static_cast<matrix_5_5<unsigned short int>>(l);
271 // CHECK-LABEL: define{{.*}} void @_Z31CastUnsignedShortIntToIntCStylev()
272 void CastUnsignedShortIntToIntCStyle() {
273 // CHECK: [[U:%.*]] = load <25 x i16>, ptr %u, align 2
274 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[U]] to <25 x i32>
275 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
276 // CHECK-NEXT: ret void
278 matrix_5_5<unsigned short int> u;
279 matrix_5_5<int> i;
280 i = (matrix_5_5<int>)u;
283 // CHECK-LABEL: define{{.*}} void @_Z35CastUnsignedShortIntToIntStaticCastv()
284 void CastUnsignedShortIntToIntStaticCast() {
285 // CHECK: [[U:%.*]] = load <25 x i16>, ptr %u, align 2
286 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[U]] to <25 x i32>
287 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4
288 // CHECK-NEXT: ret void
290 matrix_5_5<unsigned short int> u;
291 matrix_5_5<int> i;
292 i = static_cast<matrix_5_5<int>>(u);
295 // CHECK-LABEL: define{{.*}} void @_Z30CastIntToUnsignedLongIntCStylev()
296 void CastIntToUnsignedLongIntCStyle() {
297 // CHECK: [[I:%.*]] = load <25 x i32>, ptr %i, align 4
298 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i32> [[I]] to <25 x i64>
299 // CHECK-NEXT: store <25 x i64> [[CONV]], ptr {{.*}}, align 8
300 // CHECK-NEXT: ret void
302 matrix_5_5<int> i;
303 matrix_5_5<unsigned long int> u;
304 u = (matrix_5_5<unsigned long int>)i;
307 // CHECK-LABEL: define{{.*}} void @_Z34CastIntToUnsignedLongIntStaticCastv()
308 void CastIntToUnsignedLongIntStaticCast() {
309 // CHECK: [[I:%.*]] = load <25 x i32>, ptr %i, align 4
310 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i32> [[I]] to <25 x i64>
311 // CHECK-NEXT: store <25 x i64> [[CONV]], ptr {{.*}}, align 8
312 // CHECK-NEXT: ret void
314 matrix_5_5<int> i;
315 matrix_5_5<unsigned long int> u;
316 u = static_cast<matrix_5_5<unsigned long int>>(i);
319 class Foo {
320 int x[10];
322 public:
323 Foo(matrix_5_5<int> x);
326 Foo class_constructor_matrix_ty(matrix_5_5<int> m) {
327 // CHECK-LABEL: define void @_Z27class_constructor_matrix_tyu11matrix_typeILm5ELm5EiE(ptr noalias sret(%class.Foo) align 4 %agg.result, <25 x i32> noundef %m)
328 // CHECK: [[M:%.*]] = load <25 x i32>, ptr {{.*}}, align 4
329 // CHECK-NEXT: call void @_ZN3FooC1Eu11matrix_typeILm5ELm5EiE(ptr noundef nonnull align 4 dereferenceable(40) %agg.result, <25 x i32> noundef [[M]])
330 // CHECK-NEXT: ret void
332 return Foo(m);
335 struct Bar {
336 float x[10];
337 Bar(matrix_4_4<float> x);
340 Bar struct_constructor_matrix_ty(matrix_4_4<float> m) {
341 // CHECK-LABEL: define void @_Z28struct_constructor_matrix_tyu11matrix_typeILm4ELm4EfE(ptr noalias sret(%struct.Bar) align 4 %agg.result, <16 x float> noundef %m)
342 // CHECK: [[M:%.*]] = load <16 x float>, ptr {{.*}}, align 4
343 // CHECK-NEXT: call void @_ZN3BarC1Eu11matrix_typeILm4ELm4EfE(ptr noundef nonnull align 4 dereferenceable(40) %agg.result, <16 x float> noundef [[M]])
344 // CHECK-NEXT: ret void
346 return Bar(m);