1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple aarch64-linux-gnu -target-feature +neon -target-abi aapcs -ffreestanding -fallow-half-arguments-and-returns -emit-llvm -w -o - %s | FileCheck %s
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc // AAPCS clause C.8 says: If the argument has an alignment of 16 then the NGRN
4*0a6a1f1dSLionel Sambuc // is rounded up to the next even number.
5*0a6a1f1dSLionel Sambuc
6*0a6a1f1dSLionel Sambuc // CHECK: void @test1(i32 %x0, i128 %x2_x3, i128 %x4_x5, i128 %x6_x7, i128 %sp.coerce)
7*0a6a1f1dSLionel Sambuc typedef union { __int128 a; } Small;
test1(int x0,__int128 x2_x3,__int128 x4_x5,__int128 x6_x7,Small sp)8*0a6a1f1dSLionel Sambuc void test1(int x0, __int128 x2_x3, __int128 x4_x5, __int128 x6_x7, Small sp) {
9*0a6a1f1dSLionel Sambuc }
10*0a6a1f1dSLionel Sambuc
11*0a6a1f1dSLionel Sambuc
12*0a6a1f1dSLionel Sambuc // CHECK: void @test2(i32 %x0, i128 %x2_x3.coerce, i32 %x4, i128 %x6_x7.coerce, i32 %sp, i128 %sp16.coerce)
test2(int x0,Small x2_x3,int x4,Small x6_x7,int sp,Small sp16)13*0a6a1f1dSLionel Sambuc void test2(int x0, Small x2_x3, int x4, Small x6_x7, int sp, Small sp16) {
14*0a6a1f1dSLionel Sambuc }
15*0a6a1f1dSLionel Sambuc
16*0a6a1f1dSLionel Sambuc // We coerce HFAs into a contiguous [N x double] type if they're going on the
17*0a6a1f1dSLionel Sambuc // stack in order to avoid holes. Make sure we get all of them, and not just the
18*0a6a1f1dSLionel Sambuc // first:
19*0a6a1f1dSLionel Sambuc
20*0a6a1f1dSLionel Sambuc // CHECK: void @test3([4 x float] %s0_s3.coerce, float %s4, [4 x float] %sp.coerce, [4 x float] %sp16.coerce)
21*0a6a1f1dSLionel Sambuc typedef struct { float arr[4]; } HFA;
test3(HFA s0_s3,float s4,HFA sp,HFA sp16)22*0a6a1f1dSLionel Sambuc void test3(HFA s0_s3, float s4, HFA sp, HFA sp16) {
23*0a6a1f1dSLionel Sambuc }
24*0a6a1f1dSLionel Sambuc
25*0a6a1f1dSLionel Sambuc
26*0a6a1f1dSLionel Sambuc // However, we shouldn't perform the [N x double] coercion on types which have
27*0a6a1f1dSLionel Sambuc // sufficient alignment to avoid holes on their own. We could coerce to [N x
28*0a6a1f1dSLionel Sambuc // fp128] or something, but leaving them as-is retains more information for
29*0a6a1f1dSLionel Sambuc // users to debug.
30*0a6a1f1dSLionel Sambuc
31*0a6a1f1dSLionel Sambuc // CHECK: void @test4([3 x <16 x i8>] %v0_v2.coerce, [3 x <16 x i8>] %v3_v5.coerce, [3 x <16 x i8>] %sp.coerce, double %sp48, [3 x <16 x i8>] %sp64.coerce)
32*0a6a1f1dSLionel Sambuc typedef __attribute__((neon_vector_type(16))) signed char int8x16_t;
33*0a6a1f1dSLionel Sambuc typedef struct { int8x16_t arr[3]; } BigHFA;
test4(BigHFA v0_v2,BigHFA v3_v5,BigHFA sp,double sp48,BigHFA sp64)34*0a6a1f1dSLionel Sambuc void test4(BigHFA v0_v2, BigHFA v3_v5, BigHFA sp, double sp48, BigHFA sp64) {
35*0a6a1f1dSLionel Sambuc }
36*0a6a1f1dSLionel Sambuc
37*0a6a1f1dSLionel Sambuc // It's the job of the argument *consumer* to perform the required sign & zero
38*0a6a1f1dSLionel Sambuc // extensions under AAPCS. There shouldn't be
39*0a6a1f1dSLionel Sambuc
40*0a6a1f1dSLionel Sambuc // CHECK: define i8 @test5(i8 %a, i16 %b)
test5(unsigned char a,signed short b)41*0a6a1f1dSLionel Sambuc unsigned char test5(unsigned char a, signed short b) {
42*0a6a1f1dSLionel Sambuc }
43*0a6a1f1dSLionel Sambuc
44*0a6a1f1dSLionel Sambuc // __fp16 can be used as a function argument or return type (ACLE 2.0)
45*0a6a1f1dSLionel Sambuc // CHECK: define half @test_half(half %{{.*}})
test_half(__fp16 A)46*0a6a1f1dSLionel Sambuc __fp16 test_half(__fp16 A) { }
47*0a6a1f1dSLionel Sambuc
48*0a6a1f1dSLionel Sambuc // __fp16 is a base type for homogeneous floating-point aggregates for AArch64 (but not 32-bit ARM).
49*0a6a1f1dSLionel Sambuc // CHECK: define %struct.HFA_half @test_half_hfa([4 x half] %{{.*}})
50*0a6a1f1dSLionel Sambuc struct HFA_half { __fp16 a[4]; };
test_half_hfa(struct HFA_half A)51*0a6a1f1dSLionel Sambuc struct HFA_half test_half_hfa(struct HFA_half A) { }
52