1 // RUN: %clang_cc1 -triple thumbv7k-apple-watchos2.0 -target-abi aapcs16 -target-cpu cortex-a7 %s -o - -emit-llvm | FileCheck %s
2
3 #include <arm_neon.h>
4
5 // Make sure 64 and 128 bit types are naturally aligned by the v7k ABI:
6
7 // CHECK: target datalayout = "e-m:o-p:32:32-Fi8-i64:64-a:0:32-n32-S128"
8
9 typedef struct {
10 float arr[4];
11 } HFA;
12
13 // CHECK: define void @simple_hfa([4 x float] %h.coerce)
simple_hfa(HFA h)14 void simple_hfa(HFA h) {}
15
16 // CHECK: define %struct.HFA @return_simple_hfa
return_simple_hfa()17 HFA return_simple_hfa() {}
18
19 typedef struct {
20 double arr[4];
21 } BigHFA;
22
23 // We don't want any padding type to be included by Clang when using the
24 // APCS-VFP ABI, that needs to be handled by LLVM if needed.
25
26 // CHECK: void @no_padding(i32 %r0, i32 %r1, i32 %r2, [4 x double] %d0_d3.coerce, [4 x double] %d4_d7.coerce, [4 x double] %sp.coerce, i64 %split)
no_padding(int r0,int r1,int r2,BigHFA d0_d3,BigHFA d4_d7,BigHFA sp,long long split)27 void no_padding(int r0, int r1, int r2, BigHFA d0_d3, BigHFA d4_d7, BigHFA sp,
28 long long split) {}
29
30 // Structs larger than 16 bytes should be passed indirectly in space allocated
31 // by the caller (a pointer to this storage should be what occurs in the arg
32 // list).
33
34 typedef struct {
35 float x;
36 long long y;
37 double z;
38 } BigStruct;
39
40 // CHECK: define void @big_struct_indirect(%struct.BigStruct* %b)
big_struct_indirect(BigStruct b)41 void big_struct_indirect(BigStruct b) {}
42
43 // CHECK: define void @return_big_struct_indirect(%struct.BigStruct* noalias sret
return_big_struct_indirect()44 BigStruct return_big_struct_indirect() {}
45
46 // Structs smaller than 16 bytes should be passed directly, and coerced to
47 // either [N x i32] or [N x i64] depending on alignment requirements.
48
49 typedef struct {
50 float x;
51 int y;
52 double z;
53 } SmallStruct;
54
55 // CHECK: define void @small_struct_direct([2 x i64] %s.coerce)
small_struct_direct(SmallStruct s)56 void small_struct_direct(SmallStruct s) {}
57
58 // CHECK: define [4 x i32] @return_small_struct_direct()
return_small_struct_direct()59 SmallStruct return_small_struct_direct() {}
60
61 typedef struct {
62 float x;
63 int y;
64 int z;
65 } SmallStructSmallAlign;
66
67 // CHECK: define void @small_struct_align_direct([3 x i32] %s.coerce)
small_struct_align_direct(SmallStructSmallAlign s)68 void small_struct_align_direct(SmallStructSmallAlign s) {}
69
70 typedef struct {
71 char x;
72 short y;
73 } PaddedSmallStruct;
74
75 // CHECK: define i32 @return_padded_small_struct()
return_padded_small_struct()76 PaddedSmallStruct return_padded_small_struct() {}
77
78 typedef struct {
79 char arr[7];
80 } OddlySizedStruct;
81
82 // CHECK: define [2 x i32] @return_oddly_sized_struct()
return_oddly_sized_struct()83 OddlySizedStruct return_oddly_sized_struct() {}
84
85 // CHECK: define <4 x float> @test_va_arg_vec(i8* %l)
86 // CHECK: [[ALIGN_TMP:%.*]] = add i32 {{%.*}}, 15
87 // CHECK: [[ALIGNED:%.*]] = and i32 [[ALIGN_TMP]], -16
88 // CHECK: [[ALIGNED_I8:%.*]] = inttoptr i32 [[ALIGNED]] to i8*
89 // CHECK: [[ALIGNED_VEC:%.*]] = bitcast i8* [[ALIGNED_I8]] to <4 x float>
90 // CHECK: load <4 x float>, <4 x float>* [[ALIGNED_VEC]], align 16
test_va_arg_vec(__builtin_va_list l)91 float32x4_t test_va_arg_vec(__builtin_va_list l) {
92 return __builtin_va_arg(l, float32x4_t);
93 }
94