1 // RUN: %clang_cc1 -triple arm64-apple-ios7 -target-feature +neon -target-abi darwinpcs -ffreestanding -emit-llvm -w -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-LE 2 // RUN: %clang_cc1 -triple aarch64_be-none-linux-gnu -target-feature +neon -target-abi darwinpcs -ffreestanding -emit-llvm -w -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-BE 3 4 // CHECK: define{{.*}} signext i8 @f0() 5 char f0(void) { 6 return 0; 7 } 8 9 // Struct as return type. Aggregates <= 16 bytes are passed directly. For BE, 10 // return values are round up to 64 bits. 11 // 12 // CHECK-LE: define{{.*}} i8 @f1() 13 // CHECK-BE: define{{.*}} i64 @f1() 14 struct s1 { char f0; }; 15 struct s1 f1(void) {} 16 17 // CHECK-LE: define{{.*}} i16 @f2() 18 // CHECK-BE: define{{.*}} i64 @f2() 19 struct s2 { short f0; }; 20 struct s2 f2(void) {} 21 22 // CHECK-LE: define{{.*}} i32 @f3() 23 // CHECK-BE: define{{.*}} i64 @f3() 24 struct s3 { int f0; }; 25 struct s3 f3(void) {} 26 27 // CHECK-LE: define{{.*}} i32 @f4() 28 // CHECK-BE: define{{.*}} i64 @f4() 29 struct s4 { struct s4_0 { int f0; } f0; }; 30 struct s4 f4(void) {} 31 32 // CHECK-LE: define{{.*}} i32 @f5() 33 // CHECK-BE: define{{.*}} i64 @f5() 34 struct s5 { struct { } f0; int f1; }; 35 struct s5 f5(void) {} 36 37 // CHECK-LE: define{{.*}} i32 @f6() 38 // CHECK-BE: define{{.*}} i64 @f6() 39 struct s6 { int f0[1]; }; 40 struct s6 f6(void) {} 41 42 // CHECK: define{{.*}} void @f7() 43 struct s7 { struct { int : 0; } f0; }; 44 struct s7 f7(void) {} 45 46 // CHECK: define{{.*}} void @f8() 47 struct s8 { struct { int : 0; } f0[1]; }; 48 struct s8 f8(void) {} 49 50 // CHECK-LE: define{{.*}} i32 @f9() 51 // CHECK-BE: define{{.*}} i64 @f9() 52 struct s9 { int f0; int : 0; }; 53 struct s9 f9(void) {} 54 55 // CHECK-LE: define{{.*}} i32 @f10() 56 // CHECK-BE: define{{.*}} i64 @f10() 57 struct s10 { int f0; int : 0; int : 0; }; 58 struct s10 f10(void) {} 59 60 // CHECK-LE: define{{.*}} i32 @f11() 61 // CHECK-BE: define{{.*}} i64 @f11() 62 struct s11 { int : 0; int f0; }; 63 struct s11 f11(void) {} 64 65 // CHECK-LE: define{{.*}} i24 @f11_packed() 66 // CHECK-BE: define{{.*}} i64 @f11_packed() 67 struct s11_packed { char c; short s } __attribute__((packed)); 68 struct s11_packed f11_packed(void) { } 69 70 // CHECK-LE: define{{.*}} i32 @f11_not_packed() 71 // CHECK-BE: define{{.*}} i64 @f11_not_packed() 72 struct s11_not_packed { char c; short s; }; 73 struct s11_not_packed f11_not_packed(void) { } 74 75 // CHECK-LE: define{{.*}} i32 @f12() 76 // CHECK-BE: define{{.*}} i64 @f12() 77 union u12 { char f0; short f1; int f2; }; 78 union u12 f12(void) {} 79 80 // Homogeneous Aggregate as return type will be passed directly. 81 // CHECK: define{{.*}} %struct.s13 @f13() 82 struct s13 { float f0; }; 83 struct s13 f13(void) {} 84 // CHECK: define{{.*}} %union.u14 @f14() 85 union u14 { float f0; }; 86 union u14 f14(void) {} 87 88 // CHECK: define{{.*}} void @f15() 89 void f15(struct s7 a0) {} 90 91 // CHECK: define{{.*}} void @f16() 92 void f16(struct s8 a0) {} 93 94 // CHECK-LE: define{{.*}} i32 @f17() 95 // CHECK-BE: define{{.*}} i64 @f17() 96 struct s17 { short f0 : 13; char f1 : 4; }; 97 struct s17 f17(void) {} 98 99 // CHECK-LE: define{{.*}} i32 @f18() 100 // CHECK-BE: define{{.*}} i64 @f18() 101 struct s18 { short f0; char f1 : 4; }; 102 struct s18 f18(void) {} 103 104 // CHECK-LE: define{{.*}} i32 @f19() 105 // CHECK-BE: define{{.*}} i64 @f19() 106 struct s19 { int f0; struct s8 f1; }; 107 struct s19 f19(void) {} 108 109 // CHECK-LE: define{{.*}} i32 @f20() 110 // CHECK-BE: define{{.*}} i64 @f20() 111 struct s20 { struct s8 f1; int f0; }; 112 struct s20 f20(void) {} 113 114 // CHECK-LE: define{{.*}} i32 @f21() 115 // CHECK-BE: define{{.*}} i64 @f21() 116 struct s21 { struct {} f1; int f0 : 4; }; 117 struct s21 f21(void) {} 118 119 // CHECK-LE: define{{.*}} i16 @f22() 120 // CHECK-LE: define{{.*}} i32 @f23() 121 // CHECK-BE: define{{.*}} i64 @f22() 122 // CHECK-BE: define{{.*}} i64 @f23() 123 // CHECK: define{{.*}} i64 @f24() 124 // CHECK: define{{.*}} [2 x i64] @f25() 125 // CHECK: define{{.*}} { float, float } @f26() 126 // CHECK: define{{.*}} { double, double } @f27() 127 _Complex char f22(void) {} 128 _Complex short f23(void) {} 129 _Complex int f24(void) {} 130 _Complex long long f25(void) {} 131 _Complex float f26(void) {} 132 _Complex double f27(void) {} 133 134 // CHECK-LE: define{{.*}} i16 @f28() 135 // CHECK-BE: define{{.*}} i64 @f28() 136 struct s28 { _Complex char f0; }; 137 struct s28 f28() {} 138 139 // CHECK-LE: define{{.*}} i32 @f29() 140 // CHECK-BE: define{{.*}} i64 @f29() 141 struct s29 { _Complex short f0; }; 142 struct s29 f29() {} 143 144 // CHECK: define{{.*}} i64 @f30() 145 struct s30 { _Complex int f0; }; 146 struct s30 f30() {} 147 148 struct s31 { char x; }; 149 void f31(struct s31 s) { } 150 // CHECK: define{{.*}} void @f31(i64 %s.coerce) 151 // CHECK: %s = alloca %struct.s31, align 1 152 // CHECK-BE: %coerce.highbits = lshr i64 %s.coerce, 56 153 // CHECK-BE: trunc i64 %coerce.highbits to i8 154 // CHECK-LE: trunc i64 %s.coerce to i8 155 // CHECK: store i8 %{{.*}}, 156 157 struct s32 { double x; }; 158 void f32(struct s32 s) { } 159 // CHECK: @f32([1 x double] %{{.*}}) 160 161 // A composite type larger than 16 bytes should be passed indirectly. 162 struct s33 { char buf[32*32]; }; 163 void f33(struct s33 s) { } 164 // CHECK: define{{.*}} void @f33(%struct.s33* %s) 165 166 struct s34 { char c; }; 167 void f34(struct s34 s); 168 void g34(struct s34 *s) { f34(*s); } 169 // CHECK: @g34(%struct.s34* %s) 170 // CHECK: %[[a:.*]] = load i8, i8* %{{.*}} 171 // CHECK: zext i8 %[[a]] to i64 172 // CHECK: call void @f34(i64 %{{.*}}) 173 174 /* 175 * Check that va_arg accesses stack according to ABI alignment 176 */ 177 long long t1(int i, ...) { 178 // CHECK: t1 179 __builtin_va_list ap; 180 __builtin_va_start(ap, i); 181 // CHECK-NOT: add i32 %{{.*}} 7 182 // CHECK-NOT: and i32 %{{.*}} -8 183 long long ll = __builtin_va_arg(ap, long long); 184 __builtin_va_end(ap); 185 return ll; 186 } 187 double t2(int i, ...) { 188 // CHECK: t2 189 __builtin_va_list ap; 190 __builtin_va_start(ap, i); 191 // CHECK-NOT: add i32 %{{.*}} 7 192 // CHECK-NOT: and i32 %{{.*}} -8 193 double ll = __builtin_va_arg(ap, double); 194 __builtin_va_end(ap); 195 return ll; 196 } 197 198 #include <arm_neon.h> 199 200 // Homogeneous Vector Aggregate as return type and argument type. 201 // CHECK: define{{.*}} %struct.int8x16x2_t @f0_0(<16 x i8> %{{.*}}, <16 x i8> %{{.*}}) 202 int8x16x2_t f0_0(int8x16_t a0, int8x16_t a1) { 203 return vzipq_s8(a0, a1); 204 } 205 206 // Test direct vector passing. 207 typedef float T_float32x2 __attribute__ ((__vector_size__ (8))); 208 typedef float T_float32x4 __attribute__ ((__vector_size__ (16))); 209 typedef float T_float32x8 __attribute__ ((__vector_size__ (32))); 210 typedef float T_float32x16 __attribute__ ((__vector_size__ (64))); 211 212 // CHECK: define{{.*}} <2 x float> @f1_0(<2 x float> %{{.*}}) 213 T_float32x2 f1_0(T_float32x2 a0) { return a0; } 214 // CHECK: define{{.*}} <4 x float> @f1_1(<4 x float> %{{.*}}) 215 T_float32x4 f1_1(T_float32x4 a0) { return a0; } 216 // Vector with length bigger than 16-byte is illegal and is passed indirectly. 217 // CHECK: define{{.*}} void @f1_2(<8 x float>* noalias sret(<8 x float>) align 16 %{{.*}}, <8 x float>* %0) 218 T_float32x8 f1_2(T_float32x8 a0) { return a0; } 219 // CHECK: define{{.*}} void @f1_3(<16 x float>* noalias sret(<16 x float>) align 16 %{{.*}}, <16 x float>* %0) 220 T_float32x16 f1_3(T_float32x16 a0) { return a0; } 221 222 // Testing alignment with aggregates: HFA, aggregates with size <= 16 bytes and 223 // aggregates with size > 16 bytes. 224 struct s35 225 { 226 float v[4]; //Testing HFA. 227 } __attribute__((aligned(16))); 228 typedef struct s35 s35_with_align; 229 230 typedef __attribute__((neon_vector_type(4))) float float32x4_t; 231 float32x4_t f35(int i, s35_with_align s1, s35_with_align s2) { 232 // CHECK: define{{.*}} <4 x float> @f35(i32 %i, [4 x float] %s1.coerce, [4 x float] %s2.coerce) 233 // CHECK: %s1 = alloca %struct.s35, align 16 234 // CHECK: %s2 = alloca %struct.s35, align 16 235 // CHECK: %[[a:.*]] = bitcast %struct.s35* %s1 to <4 x float>* 236 // CHECK: load <4 x float>, <4 x float>* %[[a]], align 16 237 // CHECK: %[[b:.*]] = bitcast %struct.s35* %s2 to <4 x float>* 238 // CHECK: load <4 x float>, <4 x float>* %[[b]], align 16 239 float32x4_t v = vaddq_f32(*(float32x4_t *)&s1, 240 *(float32x4_t *)&s2); 241 return v; 242 } 243 244 struct s36 245 { 246 int v[4]; //Testing 16-byte aggregate. 247 } __attribute__((aligned(16))); 248 typedef struct s36 s36_with_align; 249 250 typedef __attribute__((neon_vector_type(4))) int int32x4_t; 251 int32x4_t f36(int i, s36_with_align s1, s36_with_align s2) { 252 // CHECK: define{{.*}} <4 x i32> @f36(i32 %i, i128 %s1.coerce, i128 %s2.coerce) 253 // CHECK: %s1 = alloca %struct.s36, align 16 254 // CHECK: %s2 = alloca %struct.s36, align 16 255 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 256 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 257 // CHECK: %[[a:.*]] = bitcast %struct.s36* %s1 to <4 x i32>* 258 // CHECK: load <4 x i32>, <4 x i32>* %[[a]], align 16 259 // CHECK: %[[b:.*]] = bitcast %struct.s36* %s2 to <4 x i32>* 260 // CHECK: load <4 x i32>, <4 x i32>* %[[b]], align 16 261 int32x4_t v = vaddq_s32(*(int32x4_t *)&s1, 262 *(int32x4_t *)&s2); 263 return v; 264 } 265 266 struct s37 267 { 268 int v[18]; //Testing large aggregate. 269 } __attribute__((aligned(16))); 270 typedef struct s37 s37_with_align; 271 272 int32x4_t f37(int i, s37_with_align s1, s37_with_align s2) { 273 // CHECK: define{{.*}} <4 x i32> @f37(i32 %i, %struct.s37* %s1, %struct.s37* %s2) 274 // CHECK: %[[a:.*]] = bitcast %struct.s37* %s1 to <4 x i32>* 275 // CHECK: load <4 x i32>, <4 x i32>* %[[a]], align 16 276 // CHECK: %[[b:.*]] = bitcast %struct.s37* %s2 to <4 x i32>* 277 // CHECK: load <4 x i32>, <4 x i32>* %[[b]], align 16 278 int32x4_t v = vaddq_s32(*(int32x4_t *)&s1, 279 *(int32x4_t *)&s2); 280 return v; 281 } 282 s37_with_align g37; 283 int32x4_t caller37() { 284 // CHECK: caller37 285 // CHECK: %[[a:.*]] = alloca %struct.s37, align 16 286 // CHECK: %[[b:.*]] = alloca %struct.s37, align 16 287 // CHECK: call void @llvm.memcpy 288 // CHECK: call void @llvm.memcpy 289 // CHECK: call <4 x i32> @f37(i32 3, %struct.s37* %[[a]], %struct.s37* %[[b]]) 290 return f37(3, g37, g37); 291 } 292 293 // rdar://problem/12648441 294 // Test passing structs with size < 8, < 16 and > 16 295 // with alignment of 16 and without 296 297 // structs with size <= 8 bytes, without alignment attribute 298 // passed as i64 regardless of the align attribute 299 struct s38 300 { 301 int i; 302 short s; 303 }; 304 typedef struct s38 s38_no_align; 305 // passing structs in registers 306 __attribute__ ((noinline)) 307 int f38(int i, s38_no_align s1, s38_no_align s2) { 308 // CHECK: define{{.*}} i32 @f38(i32 %i, i64 %s1.coerce, i64 %s2.coerce) 309 // CHECK: %s1 = alloca %struct.s38, align 4 310 // CHECK: %s2 = alloca %struct.s38, align 4 311 // CHECK: store i64 %s1.coerce, i64* %{{.*}}, align 4 312 // CHECK: store i64 %s2.coerce, i64* %{{.*}}, align 4 313 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 0 314 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 0 315 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 1 316 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 1 317 return s1.i + s2.i + i + s1.s + s2.s; 318 } 319 s38_no_align g38; 320 s38_no_align g38_2; 321 int caller38() { 322 // CHECK: define{{.*}} i32 @caller38() 323 // CHECK: %[[a:.*]] = load i64, i64* bitcast (%struct.s38* @g38 to i64*), align 4 324 // CHECK: %[[b:.*]] = load i64, i64* bitcast (%struct.s38* @g38_2 to i64*), align 4 325 // CHECK: call i32 @f38(i32 3, i64 %[[a]], i64 %[[b]]) 326 return f38(3, g38, g38_2); 327 } 328 // passing structs on stack 329 __attribute__ ((noinline)) 330 int f38_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 331 int i9, s38_no_align s1, s38_no_align s2) { 332 // CHECK: define{{.*}} i32 @f38_stack(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i32 %i8, i32 %i9, i64 %s1.coerce, i64 %s2.coerce) 333 // CHECK: %s1 = alloca %struct.s38, align 4 334 // CHECK: %s2 = alloca %struct.s38, align 4 335 // CHECK: store i64 %s1.coerce, i64* %{{.*}}, align 4 336 // CHECK: store i64 %s2.coerce, i64* %{{.*}}, align 4 337 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 0 338 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 0 339 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 1 340 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 1 341 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 342 } 343 int caller38_stack() { 344 // CHECK: define{{.*}} i32 @caller38_stack() 345 // CHECK: %[[a:.*]] = load i64, i64* bitcast (%struct.s38* @g38 to i64*), align 4 346 // CHECK: %[[b:.*]] = load i64, i64* bitcast (%struct.s38* @g38_2 to i64*), align 4 347 // CHECK: call i32 @f38_stack(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i64 %[[a]], i64 %[[b]]) 348 return f38_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g38, g38_2); 349 } 350 351 // structs with size <= 8 bytes, with alignment attribute 352 struct s39 353 { 354 int i; 355 short s; 356 } __attribute__((aligned(16))); 357 typedef struct s39 s39_with_align; 358 // passing aligned structs in registers 359 __attribute__ ((noinline)) 360 int f39(int i, s39_with_align s1, s39_with_align s2) { 361 // CHECK: define{{.*}} i32 @f39(i32 %i, i128 %s1.coerce, i128 %s2.coerce) 362 // CHECK: %s1 = alloca %struct.s39, align 16 363 // CHECK: %s2 = alloca %struct.s39, align 16 364 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 365 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 366 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 0 367 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 0 368 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 1 369 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 1 370 return s1.i + s2.i + i + s1.s + s2.s; 371 } 372 s39_with_align g39; 373 s39_with_align g39_2; 374 int caller39() { 375 // CHECK: define{{.*}} i32 @caller39() 376 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s39* @g39 to i128*), align 16 377 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s39* @g39_2 to i128*), align 16 378 // CHECK: call i32 @f39(i32 3, i128 %[[a]], i128 %[[b]]) 379 return f39(3, g39, g39_2); 380 } 381 // passing aligned structs on stack 382 __attribute__ ((noinline)) 383 int f39_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 384 int i9, s39_with_align s1, s39_with_align s2) { 385 // CHECK: define{{.*}} i32 @f39_stack(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i32 %i8, i32 %i9, i128 %s1.coerce, i128 %s2.coerce) 386 // CHECK: %s1 = alloca %struct.s39, align 16 387 // CHECK: %s2 = alloca %struct.s39, align 16 388 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 389 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 390 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 0 391 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 0 392 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 1 393 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 1 394 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 395 } 396 int caller39_stack() { 397 // CHECK: define{{.*}} i32 @caller39_stack() 398 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s39* @g39 to i128*), align 16 399 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s39* @g39_2 to i128*), align 16 400 // CHECK: call i32 @f39_stack(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i128 %[[a]], i128 %[[b]]) 401 return f39_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g39, g39_2); 402 } 403 404 // structs with size <= 16 bytes, without alignment attribute 405 struct s40 406 { 407 int i; 408 short s; 409 int i2; 410 short s2; 411 }; 412 typedef struct s40 s40_no_align; 413 // passing structs in registers 414 __attribute__ ((noinline)) 415 int f40(int i, s40_no_align s1, s40_no_align s2) { 416 // CHECK: define{{.*}} i32 @f40(i32 %i, [2 x i64] %s1.coerce, [2 x i64] %s2.coerce) 417 // CHECK: %s1 = alloca %struct.s40, align 4 418 // CHECK: %s2 = alloca %struct.s40, align 4 419 // CHECK: store [2 x i64] %s1.coerce, [2 x i64]* %{{.*}}, align 4 420 // CHECK: store [2 x i64] %s2.coerce, [2 x i64]* %{{.*}}, align 4 421 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 0 422 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 0 423 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 1 424 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 1 425 return s1.i + s2.i + i + s1.s + s2.s; 426 } 427 s40_no_align g40; 428 s40_no_align g40_2; 429 int caller40() { 430 // CHECK: define{{.*}} i32 @caller40() 431 // CHECK: %[[a:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40 to [2 x i64]*), align 4 432 // CHECK: %[[b:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40_2 to [2 x i64]*), align 4 433 // CHECK: call i32 @f40(i32 3, [2 x i64] %[[a]], [2 x i64] %[[b]]) 434 return f40(3, g40, g40_2); 435 } 436 // passing structs on stack 437 __attribute__ ((noinline)) 438 int f40_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 439 int i9, s40_no_align s1, s40_no_align s2) { 440 // CHECK: define{{.*}} i32 @f40_stack(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i32 %i8, i32 %i9, [2 x i64] %s1.coerce, [2 x i64] %s2.coerce) 441 // CHECK: %s1 = alloca %struct.s40, align 4 442 // CHECK: %s2 = alloca %struct.s40, align 4 443 // CHECK: store [2 x i64] %s1.coerce, [2 x i64]* %{{.*}}, align 4 444 // CHECK: store [2 x i64] %s2.coerce, [2 x i64]* %{{.*}}, align 4 445 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 0 446 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 0 447 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 1 448 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 1 449 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 450 } 451 int caller40_stack() { 452 // CHECK: define{{.*}} i32 @caller40_stack() 453 // CHECK: %[[a:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40 to [2 x i64]*), align 4 454 // CHECK: %[[b:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40_2 to [2 x i64]*), align 4 455 // CHECK: call i32 @f40_stack(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, [2 x i64] %[[a]], [2 x i64] %[[b]]) 456 return f40_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g40, g40_2); 457 } 458 459 // structs with size <= 16 bytes, with alignment attribute 460 struct s41 461 { 462 int i; 463 short s; 464 int i2; 465 short s2; 466 } __attribute__((aligned(16))); 467 typedef struct s41 s41_with_align; 468 // passing aligned structs in registers 469 __attribute__ ((noinline)) 470 int f41(int i, s41_with_align s1, s41_with_align s2) { 471 // CHECK: define{{.*}} i32 @f41(i32 %i, i128 %s1.coerce, i128 %s2.coerce) 472 // CHECK: %s1 = alloca %struct.s41, align 16 473 // CHECK: %s2 = alloca %struct.s41, align 16 474 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 475 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 476 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 0 477 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 0 478 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 1 479 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 1 480 return s1.i + s2.i + i + s1.s + s2.s; 481 } 482 s41_with_align g41; 483 s41_with_align g41_2; 484 int caller41() { 485 // CHECK: define{{.*}} i32 @caller41() 486 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s41* @g41 to i128*), align 16 487 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s41* @g41_2 to i128*), align 16 488 // CHECK: call i32 @f41(i32 3, i128 %[[a]], i128 %[[b]]) 489 return f41(3, g41, g41_2); 490 } 491 // passing aligned structs on stack 492 __attribute__ ((noinline)) 493 int f41_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 494 int i9, s41_with_align s1, s41_with_align s2) { 495 // CHECK: define{{.*}} i32 @f41_stack(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i32 %i8, i32 %i9, i128 %s1.coerce, i128 %s2.coerce) 496 // CHECK: %s1 = alloca %struct.s41, align 16 497 // CHECK: %s2 = alloca %struct.s41, align 16 498 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 499 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 500 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 0 501 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 0 502 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 1 503 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 1 504 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 505 } 506 int caller41_stack() { 507 // CHECK: define{{.*}} i32 @caller41_stack() 508 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s41* @g41 to i128*), align 16 509 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s41* @g41_2 to i128*), align 16 510 // CHECK: call i32 @f41_stack(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i128 %[[a]], i128 %[[b]]) 511 return f41_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g41, g41_2); 512 } 513 514 // structs with size > 16 bytes, without alignment attribute 515 struct s42 516 { 517 int i; 518 short s; 519 int i2; 520 short s2; 521 int i3; 522 short s3; 523 }; 524 typedef struct s42 s42_no_align; 525 // passing structs in registers 526 __attribute__ ((noinline)) 527 int f42(int i, s42_no_align s1, s42_no_align s2) { 528 // CHECK: define{{.*}} i32 @f42(i32 %i, %struct.s42* %s1, %struct.s42* %s2) 529 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 0 530 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 0 531 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 1 532 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 1 533 return s1.i + s2.i + i + s1.s + s2.s; 534 } 535 s42_no_align g42; 536 s42_no_align g42_2; 537 int caller42() { 538 // CHECK: define{{.*}} i32 @caller42() 539 // CHECK: %[[a:.*]] = alloca %struct.s42, align 4 540 // CHECK: %[[b:.*]] = alloca %struct.s42, align 4 541 // CHECK: %[[c:.*]] = bitcast %struct.s42* %[[a]] to i8* 542 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 543 // CHECK: %[[d:.*]] = bitcast %struct.s42* %[[b]] to i8* 544 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 545 // CHECK: call i32 @f42(i32 3, %struct.s42* %[[a]], %struct.s42* %[[b]]) 546 return f42(3, g42, g42_2); 547 } 548 // passing structs on stack 549 __attribute__ ((noinline)) 550 int f42_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 551 int i9, s42_no_align s1, s42_no_align s2) { 552 // CHECK: define{{.*}} i32 @f42_stack(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i32 %i8, i32 %i9, %struct.s42* %s1, %struct.s42* %s2) 553 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 0 554 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 0 555 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 1 556 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 1 557 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 558 } 559 int caller42_stack() { 560 // CHECK: define{{.*}} i32 @caller42_stack() 561 // CHECK: %[[a:.*]] = alloca %struct.s42, align 4 562 // CHECK: %[[b:.*]] = alloca %struct.s42, align 4 563 // CHECK: %[[c:.*]] = bitcast %struct.s42* %[[a]] to i8* 564 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 565 // CHECK: %[[d:.*]] = bitcast %struct.s42* %[[b]] to i8* 566 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 567 // CHECK: call i32 @f42_stack(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, %struct.s42* %[[a]], %struct.s42* %[[b]]) 568 return f42_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g42, g42_2); 569 } 570 571 // structs with size > 16 bytes, with alignment attribute 572 struct s43 573 { 574 int i; 575 short s; 576 int i2; 577 short s2; 578 int i3; 579 short s3; 580 } __attribute__((aligned(16))); 581 typedef struct s43 s43_with_align; 582 // passing aligned structs in registers 583 __attribute__ ((noinline)) 584 int f43(int i, s43_with_align s1, s43_with_align s2) { 585 // CHECK: define{{.*}} i32 @f43(i32 %i, %struct.s43* %s1, %struct.s43* %s2) 586 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 0 587 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 0 588 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 1 589 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 1 590 return s1.i + s2.i + i + s1.s + s2.s; 591 } 592 s43_with_align g43; 593 s43_with_align g43_2; 594 int caller43() { 595 // CHECK: define{{.*}} i32 @caller43() 596 // CHECK: %[[a:.*]] = alloca %struct.s43, align 16 597 // CHECK: %[[b:.*]] = alloca %struct.s43, align 16 598 // CHECK: %[[c:.*]] = bitcast %struct.s43* %[[a]] to i8* 599 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 600 // CHECK: %[[d:.*]] = bitcast %struct.s43* %[[b]] to i8* 601 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 602 // CHECK: call i32 @f43(i32 3, %struct.s43* %[[a]], %struct.s43* %[[b]]) 603 return f43(3, g43, g43_2); 604 } 605 // passing aligned structs on stack 606 __attribute__ ((noinline)) 607 int f43_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 608 int i9, s43_with_align s1, s43_with_align s2) { 609 // CHECK: define{{.*}} i32 @f43_stack(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i32 %i8, i32 %i9, %struct.s43* %s1, %struct.s43* %s2) 610 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 0 611 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 0 612 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 1 613 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 1 614 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 615 } 616 int caller43_stack() { 617 // CHECK: define{{.*}} i32 @caller43_stack() 618 // CHECK: %[[a:.*]] = alloca %struct.s43, align 16 619 // CHECK: %[[b:.*]] = alloca %struct.s43, align 16 620 // CHECK: %[[c:.*]] = bitcast %struct.s43* %[[a]] to i8* 621 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 622 // CHECK: %[[d:.*]] = bitcast %struct.s43* %[[b]] to i8* 623 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 624 // CHECK: call i32 @f43_stack(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, %struct.s43* %[[a]], %struct.s43* %[[b]]) 625 return f43_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g43, g43_2); 626 } 627 628 // rdar://13668927 629 // We should not split argument s1 between registers and stack. 630 __attribute__ ((noinline)) 631 int f40_split(int i, int i2, int i3, int i4, int i5, int i6, int i7, 632 s40_no_align s1, s40_no_align s2) { 633 // CHECK: define{{.*}} i32 @f40_split(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, [2 x i64] %s1.coerce, [2 x i64] %s2.coerce) 634 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + s1.s + s2.s; 635 } 636 int caller40_split() { 637 // CHECK: define{{.*}} i32 @caller40_split() 638 // CHECK: call i32 @f40_split(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, [2 x i64] %{{.*}} [2 x i64] %{{.*}}) 639 return f40_split(1, 2, 3, 4, 5, 6, 7, g40, g40_2); 640 } 641 642 __attribute__ ((noinline)) 643 int f41_split(int i, int i2, int i3, int i4, int i5, int i6, int i7, 644 s41_with_align s1, s41_with_align s2) { 645 // CHECK: define{{.*}} i32 @f41_split(i32 %i, i32 %i2, i32 %i3, i32 %i4, i32 %i5, i32 %i6, i32 %i7, i128 %s1.coerce, i128 %s2.coerce) 646 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + s1.s + s2.s; 647 } 648 int caller41_split() { 649 // CHECK: define{{.*}} i32 @caller41_split() 650 // CHECK: call i32 @f41_split(i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i128 %{{.*}}, i128 %{{.*}}) 651 return f41_split(1, 2, 3, 4, 5, 6, 7, g41, g41_2); 652 } 653 654 // Handle homogeneous aggregates properly in variadic functions. 655 struct HFA { 656 float a, b, c, d; 657 }; 658 659 float test_hfa(int n, ...) { 660 // CHECK-LE-LABEL: define{{.*}} float @test_hfa(i32 %n, ...) 661 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 662 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 663 664 // HFA is not indirect, so occupies its full 16 bytes on the stack. 665 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[CURLIST]], i64 16 666 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 667 668 // CHECK-LE: bitcast i8* [[CURLIST]] to %struct.HFA* 669 __builtin_va_list thelist; 670 __builtin_va_start(thelist, n); 671 struct HFA h = __builtin_va_arg(thelist, struct HFA); 672 return h.d; 673 } 674 675 float test_hfa_call(struct HFA *a) { 676 // CHECK-LABEL: define{{.*}} float @test_hfa_call(%struct.HFA* %a) 677 // CHECK: call float (i32, ...) @test_hfa(i32 1, [4 x float] {{.*}}) 678 test_hfa(1, *a); 679 } 680 681 struct TooBigHFA { 682 float a, b, c, d, e; 683 }; 684 685 float test_toobig_hfa(int n, ...) { 686 // CHECK-LE-LABEL: define{{.*}} float @test_toobig_hfa(i32 %n, ...) 687 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 688 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 689 690 // TooBigHFA is not actually an HFA, so gets passed indirectly. Only 8 bytes 691 // of stack consumed. 692 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[CURLIST]], i64 8 693 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 694 695 // CHECK-LE: [[HFAPTRPTR:%.*]] = bitcast i8* [[CURLIST]] to %struct.TooBigHFA** 696 // CHECK-LE: [[HFAPTR:%.*]] = load %struct.TooBigHFA*, %struct.TooBigHFA** [[HFAPTRPTR]] 697 __builtin_va_list thelist; 698 __builtin_va_start(thelist, n); 699 struct TooBigHFA h = __builtin_va_arg(thelist, struct TooBigHFA); 700 return h.d; 701 } 702 703 struct HVA { 704 int32x4_t a, b; 705 }; 706 707 int32x4_t test_hva(int n, ...) { 708 // CHECK-LE-LABEL: define{{.*}} <4 x i32> @test_hva(i32 %n, ...) 709 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 710 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 711 712 // HVA is not indirect, so occupies its full 16 bytes on the stack. but it 713 // must be properly aligned. 714 // CHECK-LE: [[ALIGN0:%.*]] = ptrtoint i8* [[CURLIST]] to i64 715 // CHECK-LE: [[ALIGN1:%.*]] = add i64 [[ALIGN0]], 15 716 // CHECK-LE: [[ALIGN2:%.*]] = and i64 [[ALIGN1]], -16 717 // CHECK-LE: [[ALIGNED_LIST:%.*]] = inttoptr i64 [[ALIGN2]] to i8* 718 719 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_LIST]], i64 32 720 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 721 722 // CHECK-LE: bitcast i8* [[ALIGNED_LIST]] to %struct.HVA* 723 __builtin_va_list thelist; 724 __builtin_va_start(thelist, n); 725 struct HVA h = __builtin_va_arg(thelist, struct HVA); 726 return h.b; 727 } 728 729 struct TooBigHVA { 730 int32x4_t a, b, c, d, e; 731 }; 732 733 int32x4_t test_toobig_hva(int n, ...) { 734 // CHECK-LE-LABEL: define{{.*}} <4 x i32> @test_toobig_hva(i32 %n, ...) 735 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 736 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 737 738 // TooBigHVA is not actually an HVA, so gets passed indirectly. Only 8 bytes 739 // of stack consumed. 740 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[CURLIST]], i64 8 741 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 742 743 // CHECK-LE: [[HVAPTRPTR:%.*]] = bitcast i8* [[CURLIST]] to %struct.TooBigHVA** 744 // CHECK-LE: [[HVAPTR:%.*]] = load %struct.TooBigHVA*, %struct.TooBigHVA** [[HVAPTRPTR]] 745 __builtin_va_list thelist; 746 __builtin_va_start(thelist, n); 747 struct TooBigHVA h = __builtin_va_arg(thelist, struct TooBigHVA); 748 return h.d; 749 } 750 751 typedef __attribute__((__ext_vector_type__(3))) float float32x3_t; 752 typedef struct { float32x3_t arr[4]; } HFAv3; 753 754 float32x3_t test_hva_v3(int n, ...) { 755 // CHECK-LE-LABEL: define{{.*}} <3 x float> @test_hva_v3(i32 %n, ...) 756 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 757 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 758 759 // HVA is not indirect, so occupies its full 16 bytes on the stack. but it 760 // must be properly aligned. 761 // CHECK-LE: [[ALIGN0:%.*]] = ptrtoint i8* [[CURLIST]] to i64 762 // CHECK-LE: [[ALIGN1:%.*]] = add i64 [[ALIGN0]], 15 763 // CHECK-LE: [[ALIGN2:%.*]] = and i64 [[ALIGN1]], -16 764 // CHECK-LE: [[ALIGNED_LIST:%.*]] = inttoptr i64 [[ALIGN2]] to i8* 765 766 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_LIST]], i64 64 767 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 768 769 // CHECK-LE: bitcast i8* [[ALIGNED_LIST]] to %struct.HFAv3* 770 __builtin_va_list l; 771 __builtin_va_start(l, n); 772 HFAv3 r = __builtin_va_arg(l, HFAv3); 773 return r.arr[2]; 774 } 775 776 float32x3_t test_hva_v3_call(HFAv3 *a) { 777 // CHECK-LABEL: define{{.*}} <3 x float> @test_hva_v3_call(%struct.HFAv3* %a) 778 // CHECK: call <3 x float> (i32, ...) @test_hva_v3(i32 1, [4 x <4 x float>] {{.*}}) 779 return test_hva_v3(1, *a); 780 } 781