348 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s2 3template <typename X>4using matrix_4_4 = X __attribute__((matrix_type(4, 4)));5 6template <typename Y>7using matrix_5_5 = Y __attribute__((matrix_type(5, 5)));8 9// CHECK-LABEL: define{{.*}} void @_Z25CastCharMatrixToIntCStylev()10void CastCharMatrixToIntCStyle() {11 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 112 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>13 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 414 15 matrix_5_5<char> c;16 matrix_5_5<int> i;17 i = (matrix_5_5<int>)c;18}19 20// CHECK-LABEL: define{{.*}} void @_Z29CastCharMatrixToIntStaticCastv()21void CastCharMatrixToIntStaticCast() {22 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 123 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>24 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 425 26 matrix_5_5<char> c;27 matrix_5_5<int> i;28 i = static_cast<matrix_5_5<int>>(c);29}30 31// CHECK-LABEL: define{{.*}} void @_Z33CastCharMatrixToUnsignedIntCStylev32void CastCharMatrixToUnsignedIntCStyle() {33 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 134 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>35 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 436 // CHECK-NEXT: ret void37 38 matrix_5_5<char> c;39 matrix_5_5<unsigned int> u;40 u = (matrix_5_5<unsigned int>)c;41}42 43// CHECK-LABEL: define{{.*}} void @_Z37CastCharMatrixToUnsignedIntStaticCastv44void CastCharMatrixToUnsignedIntStaticCast() {45 // CHECK: [[C:%.*]] = load <25 x i8>, ptr {{.*}}, align 146 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i8> [[C]] to <25 x i32>47 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 448 // CHECK-NEXT: ret void49 50 matrix_5_5<char> c;51 matrix_5_5<unsigned int> u;52 u = static_cast<matrix_5_5<unsigned int>>(c);53}54 55// CHECK-LABEL: define{{.*}} void @_Z38CastUnsignedLongIntMatrixToShortCStylev56void CastUnsignedLongIntMatrixToShortCStyle() {57 // CHECK: [[U:%.*]] = load <25 x i64>, ptr {{.*}}, align 858 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> {{.*}} to <25 x i16>59 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 260 // CHECK-NEXT: ret void61 62 matrix_5_5<unsigned long int> u;63 matrix_5_5<short int> s;64 s = (matrix_5_5<short int>)u;65}66 67// CHECK-LABEL: define{{.*}} void @_Z42CastUnsignedLongIntMatrixToShortStaticCastv68void CastUnsignedLongIntMatrixToShortStaticCast() {69 // CHECK: [[U:%.*]] = load <25 x i64>, ptr {{.*}}, align 870 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> {{.*}} to <25 x i16>71 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 272 // CHECK-NEXT: ret void73 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);77}78 79// CHECK-LABEL: define{{.*}} void @_Z26CastIntMatrixToShortCStylev()80void CastIntMatrixToShortCStyle() {81 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 482 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i32> [[I]] to <25 x i16>83 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 284 // CHECK-NEXT: ret void85 86 matrix_5_5<int> i;87 matrix_5_5<short int> s;88 s = (matrix_5_5<short int>)i;89}90 91// CHECK-LABEL: define{{.*}} void @_Z30CastIntMatrixToShortStaticCastv()92void CastIntMatrixToShortStaticCast() {93 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 494 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i32> [[I]] to <25 x i16>95 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 296 // CHECK-NEXT: ret void97 98 matrix_5_5<int> i;99 matrix_5_5<short int> s;100 s = static_cast<matrix_5_5<short int>>(i);101}102 103// CHECK-LABEL: define{{.*}} void @_Z26CastIntMatrixToFloatCStylev()104void CastIntMatrixToFloatCStyle() {105 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 4106 // CHECK-NEXT: [[CONV]] = sitofp <25 x i32> {{.*}} to <25 x float>107 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4108 // CHECK-NEXT: ret void109 110 matrix_5_5<int> i;111 matrix_5_5<float> f;112 f = (matrix_5_5<float>)i;113}114 115// CHECK-LABEL: define{{.*}} void @_Z30CastIntMatrixToFloatStaticCastv()116void CastIntMatrixToFloatStaticCast() {117 // CHECK: [[I:%.*]] = load <25 x i32>, ptr {{.*}}, align 4118 // CHECK-NEXT: [[CONV]] = sitofp <25 x i32> {{.*}} to <25 x float>119 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4120 // CHECK-NEXT: ret void121 122 matrix_5_5<int> i;123 matrix_5_5<float> f;124 f = static_cast<matrix_5_5<float>>(i);125}126 127// CHECK-LABEL: define{{.*}} void @_Z34CastUnsignedIntMatrixToFloatCStylev()128void CastUnsignedIntMatrixToFloatCStyle() {129 // CHECK: [[U:%.*]] = load <25 x i16>, ptr {{.*}}, align 2130 // CHECK-NEXT: [[CONV:%.*]] = uitofp <25 x i16> [[U]] to <25 x float>131 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4132 // CHECK-NEXT: ret void133 134 matrix_5_5<unsigned short int> u;135 matrix_5_5<float> f;136 f = (matrix_5_5<float>)u;137}138 139// CHECK-LABEL: define{{.*}} void @_Z38CastUnsignedIntMatrixToFloatStaticCastv()140void CastUnsignedIntMatrixToFloatStaticCast() {141 // CHECK: [[U:%.*]] = load <25 x i16>, ptr {{.*}}, align 2142 // CHECK-NEXT: [[CONV:%.*]] = uitofp <25 x i16> [[U]] to <25 x float>143 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4144 // CHECK-NEXT: ret void145 146 matrix_5_5<unsigned short int> u;147 matrix_5_5<float> f;148 f = static_cast<matrix_5_5<float>>(u);149}150 151// CHECK-LABEL: define{{.*}} void @_Z27CastDoubleMatrixToIntCStylev()152void CastDoubleMatrixToIntCStyle() {153 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8154 // CHECK-NEXT: [[CONV:%.*]] = fptosi <25 x double> [[D]] to <25 x i32>155 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4156 // CHECK-NEXT: ret void157 158 matrix_5_5<double> d;159 matrix_5_5<int> i;160 i = (matrix_5_5<int>)d;161}162 163// CHECK-LABEL: define{{.*}} void @_Z31CastDoubleMatrixToIntStaticCastv()164void CastDoubleMatrixToIntStaticCast() {165 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8166 // CHECK-NEXT: [[CONV:%.*]] = fptosi <25 x double> [[D]] to <25 x i32>167 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4168 // CHECK-NEXT: ret void169 170 matrix_5_5<double> d;171 matrix_5_5<int> i;172 i = static_cast<matrix_5_5<int>>(d);173}174 175// CHECK-LABEL: define{{.*}} void @_Z39CastFloatMatrixToUnsignedShortIntCStylev()176void CastFloatMatrixToUnsignedShortIntCStyle() {177 // CHECK: [[F:%.*]] = load <25 x float>, ptr {{.*}}, align 4178 // CHECK-NEXT: [[CONV:%.*]] = fptoui <25 x float> [[F]] to <25 x i16>179 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2180 // CHECK-NEXT: ret void181 182 matrix_5_5<float> f;183 matrix_5_5<unsigned short int> i;184 i = (matrix_5_5<unsigned short int>)f;185}186 187// CHECK-LABEL: define{{.*}} void @_Z43CastFloatMatrixToUnsignedShortIntStaticCastv()188void CastFloatMatrixToUnsignedShortIntStaticCast() {189 // CHECK: [[F:%.*]] = load <25 x float>, ptr {{.*}}, align 4190 // CHECK-NEXT: [[CONV:%.*]] = fptoui <25 x float> [[F]] to <25 x i16>191 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2192 // CHECK-NEXT: ret void193 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);197}198 199// CHECK-LABEL: define{{.*}} void @_Z29CastDoubleMatrixToFloatCStylev()200void CastDoubleMatrixToFloatCStyle() {201 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8202 // CHECK-NEXT: [[CONV:%.*]] = fptrunc <25 x double> [[D]] to <25 x float>203 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4204 // CHECK-NEXT: ret void205 206 matrix_5_5<double> d;207 matrix_5_5<float> f;208 f = (matrix_5_5<float>)d;209}210 211// CHECK-LABEL: define{{.*}} void @_Z33CastDoubleMatrixToFloatStaticCastv()212void CastDoubleMatrixToFloatStaticCast() {213 // CHECK: [[D:%.*]] = load <25 x double>, ptr {{.*}}, align 8214 // CHECK-NEXT: [[CONV:%.*]] = fptrunc <25 x double> [[D]] to <25 x float>215 // CHECK-NEXT: store <25 x float> [[CONV]], ptr {{.*}}, align 4216 // CHECK-NEXT: ret void217 218 matrix_5_5<double> d;219 matrix_5_5<float> f;220 f = static_cast<matrix_5_5<float>>(d);221}222 223// CHECK-LABEL: define{{.*}} void @_Z39CastUnsignedShortIntToUnsignedIntCStylev()224void CastUnsignedShortIntToUnsignedIntCStyle() {225 // CHECK: [[S:%.*]] = load <25 x i16>, ptr {{.*}}, align 2226 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[S]] to <25 x i32>227 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4228 // CHECK-NEXT: ret void229 230 matrix_5_5<unsigned short int> s;231 matrix_5_5<unsigned int> i;232 i = (matrix_5_5<unsigned int>)s;233}234 235// CHECK-LABEL: define{{.*}} void @_Z43CastUnsignedShortIntToUnsignedIntStaticCastv()236void CastUnsignedShortIntToUnsignedIntStaticCast() {237 // CHECK: [[S:%.*]] = load <25 x i16>, ptr {{.*}}, align 2238 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[S]] to <25 x i32>239 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4240 // CHECK-NEXT: ret void241 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);245}246 247// CHECK-LABEL: define{{.*}} void @_Z43CastUnsignedLongIntToUnsignedShortIntCStylev()248void CastUnsignedLongIntToUnsignedShortIntCStyle() {249 // CHECK: [[L:%.*]] = load <25 x i64>, ptr %l, align 8250 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> [[L]] to <25 x i16>251 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2252 // CHECK-NEXT: ret void253 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;257}258 259// CHECK-LABEL: define{{.*}} void @_Z47CastUnsignedLongIntToUnsignedShortIntStaticCastv()260void CastUnsignedLongIntToUnsignedShortIntStaticCast() {261 // CHECK: [[L:%.*]] = load <25 x i64>, ptr %l, align 8262 // CHECK-NEXT: [[CONV:%.*]] = trunc <25 x i64> [[L]] to <25 x i16>263 // CHECK-NEXT: store <25 x i16> [[CONV]], ptr {{.*}}, align 2264 // CHECK-NEXT: ret void265 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);269}270 271// CHECK-LABEL: define{{.*}} void @_Z31CastUnsignedShortIntToIntCStylev()272void CastUnsignedShortIntToIntCStyle() {273 // CHECK: [[U:%.*]] = load <25 x i16>, ptr %u, align 2274 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[U]] to <25 x i32>275 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4276 // CHECK-NEXT: ret void277 278 matrix_5_5<unsigned short int> u;279 matrix_5_5<int> i;280 i = (matrix_5_5<int>)u;281}282 283// CHECK-LABEL: define{{.*}} void @_Z35CastUnsignedShortIntToIntStaticCastv()284void CastUnsignedShortIntToIntStaticCast() {285 // CHECK: [[U:%.*]] = load <25 x i16>, ptr %u, align 2286 // CHECK-NEXT: [[CONV:%.*]] = zext <25 x i16> [[U]] to <25 x i32>287 // CHECK-NEXT: store <25 x i32> [[CONV]], ptr {{.*}}, align 4288 // CHECK-NEXT: ret void289 290 matrix_5_5<unsigned short int> u;291 matrix_5_5<int> i;292 i = static_cast<matrix_5_5<int>>(u);293}294 295// CHECK-LABEL: define{{.*}} void @_Z30CastIntToUnsignedLongIntCStylev()296void CastIntToUnsignedLongIntCStyle() {297 // CHECK: [[I:%.*]] = load <25 x i32>, ptr %i, align 4298 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i32> [[I]] to <25 x i64>299 // CHECK-NEXT: store <25 x i64> [[CONV]], ptr {{.*}}, align 8300 // CHECK-NEXT: ret void301 302 matrix_5_5<int> i;303 matrix_5_5<unsigned long int> u;304 u = (matrix_5_5<unsigned long int>)i;305}306 307// CHECK-LABEL: define{{.*}} void @_Z34CastIntToUnsignedLongIntStaticCastv()308void CastIntToUnsignedLongIntStaticCast() {309 // CHECK: [[I:%.*]] = load <25 x i32>, ptr %i, align 4310 // CHECK-NEXT: [[CONV:%.*]] = sext <25 x i32> [[I]] to <25 x i64>311 // CHECK-NEXT: store <25 x i64> [[CONV]], ptr {{.*}}, align 8312 // CHECK-NEXT: ret void313 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);317}318 319class Foo {320 int x[10];321 322public:323 Foo(matrix_5_5<int> x);324};325 326Foo class_constructor_matrix_ty(matrix_5_5<int> m) {327 // CHECK-LABEL: define void @_Z27class_constructor_matrix_tyu11matrix_typeILm5ELm5EiE(ptr dead_on_unwind noalias writable sret(%class.Foo) align 4 %agg.result, <25 x i32> noundef %m)328 // CHECK: [[M:%.*]] = load <25 x i32>, ptr {{.*}}, align 4329 // CHECK-NEXT: call void @_ZN3FooC1Eu11matrix_typeILm5ELm5EiE(ptr noundef nonnull align 4 dereferenceable(40) %agg.result, <25 x i32> noundef [[M]])330 // CHECK-NEXT: ret void331 332 return Foo(m);333}334 335struct Bar {336 float x[10];337 Bar(matrix_4_4<float> x);338};339 340Bar struct_constructor_matrix_ty(matrix_4_4<float> m) {341 // CHECK-LABEL: define void @_Z28struct_constructor_matrix_tyu11matrix_typeILm4ELm4EfE(ptr dead_on_unwind noalias writable sret(%struct.Bar) align 4 %agg.result, <16 x float> noundef %m)342 // CHECK: [[M:%.*]] = load <16 x float>, ptr {{.*}}, align 4343 // CHECK-NEXT: call void @_ZN3BarC1Eu11matrix_typeILm4ELm4EfE(ptr noundef nonnull align 4 dereferenceable(40) %agg.result, <16 x float> noundef [[M]])344 // CHECK-NEXT: ret void345 346 return Bar(m);347}348