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