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 // 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 200 #include <arm_neon.h> 201 202 // Homogeneous Vector Aggregate as return type and argument type. 203 // CHECK: define{{.*}} %struct.int8x16x2_t @f0_0(<16 x i8> noundef %{{.*}}, <16 x i8> noundef %{{.*}}) 204 int8x16x2_t f0_0(int8x16_t a0, int8x16_t a1) { 205 return vzipq_s8(a0, a1); 206 } 207 208 // Test direct vector passing. 209 typedef float T_float32x2 __attribute__ ((__vector_size__ (8))); 210 typedef float T_float32x4 __attribute__ ((__vector_size__ (16))); 211 typedef float T_float32x8 __attribute__ ((__vector_size__ (32))); 212 typedef float T_float32x16 __attribute__ ((__vector_size__ (64))); 213 214 // CHECK: define{{.*}} <2 x float> @f1_0(<2 x float> noundef %{{.*}}) 215 T_float32x2 f1_0(T_float32x2 a0) { return a0; } 216 // CHECK: define{{.*}} <4 x float> @f1_1(<4 x float> noundef %{{.*}}) 217 T_float32x4 f1_1(T_float32x4 a0) { return a0; } 218 // Vector with length bigger than 16-byte is illegal and is passed indirectly. 219 // CHECK: define{{.*}} void @f1_2(<8 x float>* noalias sret(<8 x float>) align 16 %{{.*}}, <8 x float>* noundef %0) 220 T_float32x8 f1_2(T_float32x8 a0) { return a0; } 221 // CHECK: define{{.*}} void @f1_3(<16 x float>* noalias sret(<16 x float>) align 16 %{{.*}}, <16 x float>* noundef %0) 222 T_float32x16 f1_3(T_float32x16 a0) { return a0; } 223 224 // Testing alignment with aggregates: HFA, aggregates with size <= 16 bytes and 225 // aggregates with size > 16 bytes. 226 struct s35 227 { 228 float v[4]; //Testing HFA. 229 } __attribute__((aligned(16))); 230 typedef struct s35 s35_with_align; 231 232 typedef __attribute__((neon_vector_type(4))) float float32x4_t; 233 float32x4_t f35(int i, s35_with_align s1, s35_with_align s2) { 234 // CHECK: define{{.*}} <4 x float> @f35(i32 noundef %i, [4 x float] %s1.coerce, [4 x float] %s2.coerce) 235 // CHECK: %s1 = alloca %struct.s35, align 16 236 // CHECK: %s2 = alloca %struct.s35, align 16 237 // CHECK: %[[a:.*]] = bitcast %struct.s35* %s1 to <4 x float>* 238 // CHECK: load <4 x float>, <4 x float>* %[[a]], align 16 239 // CHECK: %[[b:.*]] = bitcast %struct.s35* %s2 to <4 x float>* 240 // CHECK: load <4 x float>, <4 x float>* %[[b]], align 16 241 float32x4_t v = vaddq_f32(*(float32x4_t *)&s1, 242 *(float32x4_t *)&s2); 243 return v; 244 } 245 246 struct s36 247 { 248 int v[4]; //Testing 16-byte aggregate. 249 } __attribute__((aligned(16))); 250 typedef struct s36 s36_with_align; 251 252 typedef __attribute__((neon_vector_type(4))) int int32x4_t; 253 int32x4_t f36(int i, s36_with_align s1, s36_with_align s2) { 254 // CHECK: define{{.*}} <4 x i32> @f36(i32 noundef %i, i128 %s1.coerce, i128 %s2.coerce) 255 // CHECK: %s1 = alloca %struct.s36, align 16 256 // CHECK: %s2 = alloca %struct.s36, align 16 257 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 258 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 259 // CHECK: %[[a:.*]] = bitcast %struct.s36* %s1 to <4 x i32>* 260 // CHECK: load <4 x i32>, <4 x i32>* %[[a]], align 16 261 // CHECK: %[[b:.*]] = bitcast %struct.s36* %s2 to <4 x i32>* 262 // CHECK: load <4 x i32>, <4 x i32>* %[[b]], align 16 263 int32x4_t v = vaddq_s32(*(int32x4_t *)&s1, 264 *(int32x4_t *)&s2); 265 return v; 266 } 267 268 struct s37 269 { 270 int v[18]; //Testing large aggregate. 271 } __attribute__((aligned(16))); 272 typedef struct s37 s37_with_align; 273 274 int32x4_t f37(int i, s37_with_align s1, s37_with_align s2) { 275 // CHECK: define{{.*}} <4 x i32> @f37(i32 noundef %i, %struct.s37* noundef %s1, %struct.s37* noundef %s2) 276 // CHECK: %[[a:.*]] = bitcast %struct.s37* %s1 to <4 x i32>* 277 // CHECK: load <4 x i32>, <4 x i32>* %[[a]], align 16 278 // CHECK: %[[b:.*]] = bitcast %struct.s37* %s2 to <4 x i32>* 279 // CHECK: load <4 x i32>, <4 x i32>* %[[b]], align 16 280 int32x4_t v = vaddq_s32(*(int32x4_t *)&s1, 281 *(int32x4_t *)&s2); 282 return v; 283 } 284 s37_with_align g37; 285 int32x4_t caller37() { 286 // CHECK: caller37 287 // CHECK: %[[a:.*]] = alloca %struct.s37, align 16 288 // CHECK: %[[b:.*]] = alloca %struct.s37, align 16 289 // CHECK: call void @llvm.memcpy 290 // CHECK: call void @llvm.memcpy 291 // CHECK: call <4 x i32> @f37(i32 noundef 3, %struct.s37* noundef %[[a]], %struct.s37* noundef %[[b]]) 292 return f37(3, g37, g37); 293 } 294 295 // rdar://problem/12648441 296 // Test passing structs with size < 8, < 16 and > 16 297 // with alignment of 16 and without 298 299 // structs with size <= 8 bytes, without alignment attribute 300 // passed as i64 regardless of the align attribute 301 struct s38 302 { 303 int i; 304 short s; 305 }; 306 typedef struct s38 s38_no_align; 307 // passing structs in registers 308 __attribute__ ((noinline)) 309 int f38(int i, s38_no_align s1, s38_no_align s2) { 310 // CHECK: define{{.*}} i32 @f38(i32 noundef %i, i64 %s1.coerce, i64 %s2.coerce) 311 // CHECK: %s1 = alloca %struct.s38, align 4 312 // CHECK: %s2 = alloca %struct.s38, align 4 313 // CHECK: store i64 %s1.coerce, i64* %{{.*}}, align 4 314 // CHECK: store i64 %s2.coerce, i64* %{{.*}}, align 4 315 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 0 316 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 0 317 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 1 318 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 1 319 return s1.i + s2.i + i + s1.s + s2.s; 320 } 321 s38_no_align g38; 322 s38_no_align g38_2; 323 int caller38() { 324 // CHECK: define{{.*}} i32 @caller38() 325 // CHECK: %[[a:.*]] = load i64, i64* bitcast (%struct.s38* @g38 to i64*), align 4 326 // CHECK: %[[b:.*]] = load i64, i64* bitcast (%struct.s38* @g38_2 to i64*), align 4 327 // CHECK: call i32 @f38(i32 noundef 3, i64 %[[a]], i64 %[[b]]) 328 return f38(3, g38, g38_2); 329 } 330 // passing structs on stack 331 __attribute__ ((noinline)) 332 int f38_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 333 int i9, s38_no_align s1, s38_no_align s2) { 334 // 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) 335 // CHECK: %s1 = alloca %struct.s38, align 4 336 // CHECK: %s2 = alloca %struct.s38, align 4 337 // CHECK: store i64 %s1.coerce, i64* %{{.*}}, align 4 338 // CHECK: store i64 %s2.coerce, i64* %{{.*}}, align 4 339 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 0 340 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 0 341 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s1, i32 0, i32 1 342 // CHECK: getelementptr inbounds %struct.s38, %struct.s38* %s2, i32 0, i32 1 343 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 344 } 345 int caller38_stack() { 346 // CHECK: define{{.*}} i32 @caller38_stack() 347 // CHECK: %[[a:.*]] = load i64, i64* bitcast (%struct.s38* @g38 to i64*), align 4 348 // CHECK: %[[b:.*]] = load i64, i64* bitcast (%struct.s38* @g38_2 to i64*), align 4 349 // 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]]) 350 return f38_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g38, g38_2); 351 } 352 353 // structs with size <= 8 bytes, with alignment attribute 354 struct s39 355 { 356 int i; 357 short s; 358 } __attribute__((aligned(16))); 359 typedef struct s39 s39_with_align; 360 // passing aligned structs in registers 361 __attribute__ ((noinline)) 362 int f39(int i, s39_with_align s1, s39_with_align s2) { 363 // CHECK: define{{.*}} i32 @f39(i32 noundef %i, i128 %s1.coerce, i128 %s2.coerce) 364 // CHECK: %s1 = alloca %struct.s39, align 16 365 // CHECK: %s2 = alloca %struct.s39, align 16 366 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 367 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 368 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 0 369 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 0 370 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 1 371 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 1 372 return s1.i + s2.i + i + s1.s + s2.s; 373 } 374 s39_with_align g39; 375 s39_with_align g39_2; 376 int caller39() { 377 // CHECK: define{{.*}} i32 @caller39() 378 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s39* @g39 to i128*), align 16 379 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s39* @g39_2 to i128*), align 16 380 // CHECK: call i32 @f39(i32 noundef 3, i128 %[[a]], i128 %[[b]]) 381 return f39(3, g39, g39_2); 382 } 383 // passing aligned structs on stack 384 __attribute__ ((noinline)) 385 int f39_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 386 int i9, s39_with_align s1, s39_with_align s2) { 387 // 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) 388 // CHECK: %s1 = alloca %struct.s39, align 16 389 // CHECK: %s2 = alloca %struct.s39, align 16 390 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 391 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 392 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 0 393 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 0 394 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s1, i32 0, i32 1 395 // CHECK: getelementptr inbounds %struct.s39, %struct.s39* %s2, i32 0, i32 1 396 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 397 } 398 int caller39_stack() { 399 // CHECK: define{{.*}} i32 @caller39_stack() 400 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s39* @g39 to i128*), align 16 401 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s39* @g39_2 to i128*), align 16 402 // 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]]) 403 return f39_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g39, g39_2); 404 } 405 406 // structs with size <= 16 bytes, without alignment attribute 407 struct s40 408 { 409 int i; 410 short s; 411 int i2; 412 short s2; 413 }; 414 typedef struct s40 s40_no_align; 415 // passing structs in registers 416 __attribute__ ((noinline)) 417 int f40(int i, s40_no_align s1, s40_no_align s2) { 418 // CHECK: define{{.*}} i32 @f40(i32 noundef %i, [2 x i64] %s1.coerce, [2 x i64] %s2.coerce) 419 // CHECK: %s1 = alloca %struct.s40, align 4 420 // CHECK: %s2 = alloca %struct.s40, align 4 421 // CHECK: store [2 x i64] %s1.coerce, [2 x i64]* %{{.*}}, align 4 422 // CHECK: store [2 x i64] %s2.coerce, [2 x i64]* %{{.*}}, align 4 423 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 0 424 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 0 425 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 1 426 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 1 427 return s1.i + s2.i + i + s1.s + s2.s; 428 } 429 s40_no_align g40; 430 s40_no_align g40_2; 431 int caller40() { 432 // CHECK: define{{.*}} i32 @caller40() 433 // CHECK: %[[a:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40 to [2 x i64]*), align 4 434 // CHECK: %[[b:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40_2 to [2 x i64]*), align 4 435 // CHECK: call i32 @f40(i32 noundef 3, [2 x i64] %[[a]], [2 x i64] %[[b]]) 436 return f40(3, g40, g40_2); 437 } 438 // passing structs on stack 439 __attribute__ ((noinline)) 440 int f40_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 441 int i9, s40_no_align s1, s40_no_align s2) { 442 // 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) 443 // CHECK: %s1 = alloca %struct.s40, align 4 444 // CHECK: %s2 = alloca %struct.s40, align 4 445 // CHECK: store [2 x i64] %s1.coerce, [2 x i64]* %{{.*}}, align 4 446 // CHECK: store [2 x i64] %s2.coerce, [2 x i64]* %{{.*}}, align 4 447 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 0 448 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 0 449 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s1, i32 0, i32 1 450 // CHECK: getelementptr inbounds %struct.s40, %struct.s40* %s2, i32 0, i32 1 451 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 452 } 453 int caller40_stack() { 454 // CHECK: define{{.*}} i32 @caller40_stack() 455 // CHECK: %[[a:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40 to [2 x i64]*), align 4 456 // CHECK: %[[b:.*]] = load [2 x i64], [2 x i64]* bitcast (%struct.s40* @g40_2 to [2 x i64]*), align 4 457 // 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]]) 458 return f40_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g40, g40_2); 459 } 460 461 // structs with size <= 16 bytes, with alignment attribute 462 struct s41 463 { 464 int i; 465 short s; 466 int i2; 467 short s2; 468 } __attribute__((aligned(16))); 469 typedef struct s41 s41_with_align; 470 // passing aligned structs in registers 471 __attribute__ ((noinline)) 472 int f41(int i, s41_with_align s1, s41_with_align s2) { 473 // CHECK: define{{.*}} i32 @f41(i32 noundef %i, i128 %s1.coerce, i128 %s2.coerce) 474 // CHECK: %s1 = alloca %struct.s41, align 16 475 // CHECK: %s2 = alloca %struct.s41, align 16 476 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 477 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 478 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 0 479 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 0 480 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 1 481 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 1 482 return s1.i + s2.i + i + s1.s + s2.s; 483 } 484 s41_with_align g41; 485 s41_with_align g41_2; 486 int caller41() { 487 // CHECK: define{{.*}} i32 @caller41() 488 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s41* @g41 to i128*), align 16 489 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s41* @g41_2 to i128*), align 16 490 // CHECK: call i32 @f41(i32 noundef 3, i128 %[[a]], i128 %[[b]]) 491 return f41(3, g41, g41_2); 492 } 493 // passing aligned structs on stack 494 __attribute__ ((noinline)) 495 int f41_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 496 int i9, s41_with_align s1, s41_with_align s2) { 497 // 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) 498 // CHECK: %s1 = alloca %struct.s41, align 16 499 // CHECK: %s2 = alloca %struct.s41, align 16 500 // CHECK: store i128 %s1.coerce, i128* %{{.*}}, align 16 501 // CHECK: store i128 %s2.coerce, i128* %{{.*}}, align 16 502 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 0 503 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 0 504 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s1, i32 0, i32 1 505 // CHECK: getelementptr inbounds %struct.s41, %struct.s41* %s2, i32 0, i32 1 506 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 507 } 508 int caller41_stack() { 509 // CHECK: define{{.*}} i32 @caller41_stack() 510 // CHECK: %[[a:.*]] = load i128, i128* bitcast (%struct.s41* @g41 to i128*), align 16 511 // CHECK: %[[b:.*]] = load i128, i128* bitcast (%struct.s41* @g41_2 to i128*), align 16 512 // 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]]) 513 return f41_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g41, g41_2); 514 } 515 516 // structs with size > 16 bytes, without alignment attribute 517 struct s42 518 { 519 int i; 520 short s; 521 int i2; 522 short s2; 523 int i3; 524 short s3; 525 }; 526 typedef struct s42 s42_no_align; 527 // passing structs in registers 528 __attribute__ ((noinline)) 529 int f42(int i, s42_no_align s1, s42_no_align s2) { 530 // CHECK: define{{.*}} i32 @f42(i32 noundef %i, %struct.s42* noundef %s1, %struct.s42* noundef %s2) 531 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 0 532 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 0 533 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 1 534 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 1 535 return s1.i + s2.i + i + s1.s + s2.s; 536 } 537 s42_no_align g42; 538 s42_no_align g42_2; 539 int caller42() { 540 // CHECK: define{{.*}} i32 @caller42() 541 // CHECK: %[[a:.*]] = alloca %struct.s42, align 4 542 // CHECK: %[[b:.*]] = alloca %struct.s42, align 4 543 // CHECK: %[[c:.*]] = bitcast %struct.s42* %[[a]] to i8* 544 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 545 // CHECK: %[[d:.*]] = bitcast %struct.s42* %[[b]] to i8* 546 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 547 // CHECK: call i32 @f42(i32 noundef 3, %struct.s42* noundef %[[a]], %struct.s42* noundef %[[b]]) 548 return f42(3, g42, g42_2); 549 } 550 // passing structs on stack 551 __attribute__ ((noinline)) 552 int f42_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 553 int i9, s42_no_align s1, s42_no_align s2) { 554 // 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) 555 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 0 556 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 0 557 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s1, i32 0, i32 1 558 // CHECK: getelementptr inbounds %struct.s42, %struct.s42* %s2, i32 0, i32 1 559 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 560 } 561 int caller42_stack() { 562 // CHECK: define{{.*}} i32 @caller42_stack() 563 // CHECK: %[[a:.*]] = alloca %struct.s42, align 4 564 // CHECK: %[[b:.*]] = alloca %struct.s42, align 4 565 // CHECK: %[[c:.*]] = bitcast %struct.s42* %[[a]] to i8* 566 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 567 // CHECK: %[[d:.*]] = bitcast %struct.s42* %[[b]] to i8* 568 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 569 // 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]]) 570 return f42_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g42, g42_2); 571 } 572 573 // structs with size > 16 bytes, with alignment attribute 574 struct s43 575 { 576 int i; 577 short s; 578 int i2; 579 short s2; 580 int i3; 581 short s3; 582 } __attribute__((aligned(16))); 583 typedef struct s43 s43_with_align; 584 // passing aligned structs in registers 585 __attribute__ ((noinline)) 586 int f43(int i, s43_with_align s1, s43_with_align s2) { 587 // CHECK: define{{.*}} i32 @f43(i32 noundef %i, %struct.s43* noundef %s1, %struct.s43* noundef %s2) 588 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 0 589 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 0 590 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 1 591 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 1 592 return s1.i + s2.i + i + s1.s + s2.s; 593 } 594 s43_with_align g43; 595 s43_with_align g43_2; 596 int caller43() { 597 // CHECK: define{{.*}} i32 @caller43() 598 // CHECK: %[[a:.*]] = alloca %struct.s43, align 16 599 // CHECK: %[[b:.*]] = alloca %struct.s43, align 16 600 // CHECK: %[[c:.*]] = bitcast %struct.s43* %[[a]] to i8* 601 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 602 // CHECK: %[[d:.*]] = bitcast %struct.s43* %[[b]] to i8* 603 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 604 // CHECK: call i32 @f43(i32 noundef 3, %struct.s43* noundef %[[a]], %struct.s43* noundef %[[b]]) 605 return f43(3, g43, g43_2); 606 } 607 // passing aligned structs on stack 608 __attribute__ ((noinline)) 609 int f43_stack(int i, int i2, int i3, int i4, int i5, int i6, int i7, int i8, 610 int i9, s43_with_align s1, s43_with_align s2) { 611 // 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) 612 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 0 613 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 0 614 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s1, i32 0, i32 1 615 // CHECK: getelementptr inbounds %struct.s43, %struct.s43* %s2, i32 0, i32 1 616 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 + s1.s + s2.s; 617 } 618 int caller43_stack() { 619 // CHECK: define{{.*}} i32 @caller43_stack() 620 // CHECK: %[[a:.*]] = alloca %struct.s43, align 16 621 // CHECK: %[[b:.*]] = alloca %struct.s43, align 16 622 // CHECK: %[[c:.*]] = bitcast %struct.s43* %[[a]] to i8* 623 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 624 // CHECK: %[[d:.*]] = bitcast %struct.s43* %[[b]] to i8* 625 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64 626 // 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]]) 627 return f43_stack(1, 2, 3, 4, 5, 6, 7, 8, 9, g43, g43_2); 628 } 629 630 // rdar://13668927 631 // We should not split argument s1 between registers and stack. 632 __attribute__ ((noinline)) 633 int f40_split(int i, int i2, int i3, int i4, int i5, int i6, int i7, 634 s40_no_align s1, s40_no_align s2) { 635 // 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) 636 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + s1.s + s2.s; 637 } 638 int caller40_split() { 639 // CHECK: define{{.*}} i32 @caller40_split() 640 // 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] %{{.*}}) 641 return f40_split(1, 2, 3, 4, 5, 6, 7, g40, g40_2); 642 } 643 644 __attribute__ ((noinline)) 645 int f41_split(int i, int i2, int i3, int i4, int i5, int i6, int i7, 646 s41_with_align s1, s41_with_align s2) { 647 // 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) 648 return s1.i + s2.i + i + i2 + i3 + i4 + i5 + i6 + i7 + s1.s + s2.s; 649 } 650 int caller41_split() { 651 // CHECK: define{{.*}} i32 @caller41_split() 652 // 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 %{{.*}}) 653 return f41_split(1, 2, 3, 4, 5, 6, 7, g41, g41_2); 654 } 655 656 // Handle homogeneous aggregates properly in variadic functions. 657 struct HFA { 658 float a, b, c, d; 659 }; 660 661 float test_hfa(int n, ...) { 662 // CHECK-LE-LABEL: define{{.*}} float @test_hfa(i32 noundef %n, ...) 663 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 664 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 665 666 // HFA is not indirect, so occupies its full 16 bytes on the stack. 667 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[CURLIST]], i64 16 668 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 669 670 // CHECK-LE: bitcast i8* [[CURLIST]] to %struct.HFA* 671 __builtin_va_list thelist; 672 __builtin_va_start(thelist, n); 673 struct HFA h = __builtin_va_arg(thelist, struct HFA); 674 return h.d; 675 } 676 677 float test_hfa_call(struct HFA *a) { 678 // CHECK-LABEL: define{{.*}} float @test_hfa_call(%struct.HFA* noundef %a) 679 // CHECK: call float (i32, ...) @test_hfa(i32 noundef 1, [4 x float] {{.*}}) 680 test_hfa(1, *a); 681 } 682 683 struct TooBigHFA { 684 float a, b, c, d, e; 685 }; 686 687 float test_toobig_hfa(int n, ...) { 688 // CHECK-LE-LABEL: define{{.*}} float @test_toobig_hfa(i32 noundef %n, ...) 689 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 690 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 691 692 // TooBigHFA is not actually an HFA, so gets passed indirectly. Only 8 bytes 693 // of stack consumed. 694 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[CURLIST]], i64 8 695 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 696 697 // CHECK-LE: [[HFAPTRPTR:%.*]] = bitcast i8* [[CURLIST]] to %struct.TooBigHFA** 698 // CHECK-LE: [[HFAPTR:%.*]] = load %struct.TooBigHFA*, %struct.TooBigHFA** [[HFAPTRPTR]] 699 __builtin_va_list thelist; 700 __builtin_va_start(thelist, n); 701 struct TooBigHFA h = __builtin_va_arg(thelist, struct TooBigHFA); 702 return h.d; 703 } 704 705 struct HVA { 706 int32x4_t a, b; 707 }; 708 709 int32x4_t test_hva(int n, ...) { 710 // CHECK-LE-LABEL: define{{.*}} <4 x i32> @test_hva(i32 noundef %n, ...) 711 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 712 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 713 714 // HVA is not indirect, so occupies its full 16 bytes on the stack. but it 715 // must be properly aligned. 716 // CHECK-LE: [[ALIGN0:%.*]] = ptrtoint i8* [[CURLIST]] to i64 717 // CHECK-LE: [[ALIGN1:%.*]] = add i64 [[ALIGN0]], 15 718 // CHECK-LE: [[ALIGN2:%.*]] = and i64 [[ALIGN1]], -16 719 // CHECK-LE: [[ALIGNED_LIST:%.*]] = inttoptr i64 [[ALIGN2]] to i8* 720 721 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_LIST]], i64 32 722 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 723 724 // CHECK-LE: bitcast i8* [[ALIGNED_LIST]] to %struct.HVA* 725 __builtin_va_list thelist; 726 __builtin_va_start(thelist, n); 727 struct HVA h = __builtin_va_arg(thelist, struct HVA); 728 return h.b; 729 } 730 731 struct TooBigHVA { 732 int32x4_t a, b, c, d, e; 733 }; 734 735 int32x4_t test_toobig_hva(int n, ...) { 736 // CHECK-LE-LABEL: define{{.*}} <4 x i32> @test_toobig_hva(i32 noundef %n, ...) 737 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 738 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 739 740 // TooBigHVA is not actually an HVA, so gets passed indirectly. Only 8 bytes 741 // of stack consumed. 742 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[CURLIST]], i64 8 743 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 744 745 // CHECK-LE: [[HVAPTRPTR:%.*]] = bitcast i8* [[CURLIST]] to %struct.TooBigHVA** 746 // CHECK-LE: [[HVAPTR:%.*]] = load %struct.TooBigHVA*, %struct.TooBigHVA** [[HVAPTRPTR]] 747 __builtin_va_list thelist; 748 __builtin_va_start(thelist, n); 749 struct TooBigHVA h = __builtin_va_arg(thelist, struct TooBigHVA); 750 return h.d; 751 } 752 753 typedef __attribute__((__ext_vector_type__(3))) float float32x3_t; 754 typedef struct { float32x3_t arr[4]; } HFAv3; 755 756 float32x3_t test_hva_v3(int n, ...) { 757 // CHECK-LE-LABEL: define{{.*}} <3 x float> @test_hva_v3(i32 noundef %n, ...) 758 // CHECK-LE: [[THELIST:%.*]] = alloca i8* 759 // CHECK-LE: [[CURLIST:%.*]] = load i8*, i8** [[THELIST]] 760 761 // HVA is not indirect, so occupies its full 16 bytes on the stack. but it 762 // must be properly aligned. 763 // CHECK-LE: [[ALIGN0:%.*]] = ptrtoint i8* [[CURLIST]] to i64 764 // CHECK-LE: [[ALIGN1:%.*]] = add i64 [[ALIGN0]], 15 765 // CHECK-LE: [[ALIGN2:%.*]] = and i64 [[ALIGN1]], -16 766 // CHECK-LE: [[ALIGNED_LIST:%.*]] = inttoptr i64 [[ALIGN2]] to i8* 767 768 // CHECK-LE: [[NEXTLIST:%.*]] = getelementptr inbounds i8, i8* [[ALIGNED_LIST]], i64 64 769 // CHECK-LE: store i8* [[NEXTLIST]], i8** [[THELIST]] 770 771 // CHECK-LE: bitcast i8* [[ALIGNED_LIST]] to %struct.HFAv3* 772 __builtin_va_list l; 773 __builtin_va_start(l, n); 774 HFAv3 r = __builtin_va_arg(l, HFAv3); 775 return r.arr[2]; 776 } 777 778 float32x3_t test_hva_v3_call(HFAv3 *a) { 779 // CHECK-LABEL: define{{.*}} <3 x float> @test_hva_v3_call(%struct.HFAv3* noundef %a) 780 // CHECK: call <3 x float> (i32, ...) @test_hva_v3(i32 noundef 1, [4 x <4 x float>] {{.*}}) 781 return test_hva_v3(1, *a); 782 } 783