blob: 8c4437a38d0a5a29d86f7c63399a80a04e5d22b8 [file] [log] [blame]
Stephen Hinesc568f1e2014-07-21 00:47:37 -07001// RUN: %clang_cc1 -faltivec -triple powerpc64-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
2
3#include <stdarg.h>
4
5struct test1 { int x; int y; };
6struct test2 { int x; int y; } __attribute__((aligned (16)));
7struct test3 { int x; int y; } __attribute__((aligned (32)));
8struct test4 { int x; int y; int z; };
Stephen Hines176edba2014-12-01 14:53:08 -08009struct test5 { int x[17]; };
10struct test6 { int x[17]; } __attribute__((aligned (16)));
11struct test7 { int x[17]; } __attribute__((aligned (32)));
Stephen Hinesc568f1e2014-07-21 00:47:37 -070012
Stephen Hines176edba2014-12-01 14:53:08 -080013// CHECK: define void @test1(i32 signext %x, i64 %y.coerce)
Stephen Hinesc568f1e2014-07-21 00:47:37 -070014void test1 (int x, struct test1 y)
15{
16}
17
Stephen Hines176edba2014-12-01 14:53:08 -080018// CHECK: define void @test2(i32 signext %x, [1 x i128] %y.coerce)
Stephen Hinesc568f1e2014-07-21 00:47:37 -070019void test2 (int x, struct test2 y)
20{
21}
22
Stephen Hines176edba2014-12-01 14:53:08 -080023// CHECK: define void @test3(i32 signext %x, [2 x i128] %y.coerce)
Stephen Hinesc568f1e2014-07-21 00:47:37 -070024void test3 (int x, struct test3 y)
25{
26}
27
Stephen Hines176edba2014-12-01 14:53:08 -080028// CHECK: define void @test4(i32 signext %x, [2 x i64] %y.coerce)
Stephen Hinesc568f1e2014-07-21 00:47:37 -070029void test4 (int x, struct test4 y)
30{
31}
32
Stephen Hines176edba2014-12-01 14:53:08 -080033// CHECK: define void @test5(i32 signext %x, %struct.test5* byval align 8 %y)
34void test5 (int x, struct test5 y)
35{
36}
37
38// CHECK: define void @test6(i32 signext %x, %struct.test6* byval align 16 %y)
39void test6 (int x, struct test6 y)
40{
41}
42
43// This case requires run-time realignment of the incoming struct
44// CHECK: define void @test7(i32 signext %x, %struct.test7* byval align 16)
45// CHECK: %y = alloca %struct.test7, align 32
46// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
47void test7 (int x, struct test7 y)
48{
49}
50
Stephen Hinesc568f1e2014-07-21 00:47:37 -070051// CHECK: define void @test1va(%struct.test1* noalias sret %agg.result, i32 signext %x, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070052// CHECK: %[[CUR:[^ ]+]] = load i8*, i8** %ap
53// CHECK: %[[NEXT:[^ ]+]] = getelementptr i8, i8* %[[CUR]], i64 8
Stephen Hines176edba2014-12-01 14:53:08 -080054// CHECK: store i8* %[[NEXT]], i8** %ap
55// CHECK: bitcast i8* %[[CUR]] to %struct.test1*
Stephen Hinesc568f1e2014-07-21 00:47:37 -070056struct test1 test1va (int x, ...)
57{
58 struct test1 y;
59 va_list ap;
60 va_start(ap, x);
61 y = va_arg (ap, struct test1);
62 va_end(ap);
63 return y;
64}
65
66// CHECK: define void @test2va(%struct.test2* noalias sret %agg.result, i32 signext %x, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070067// CHECK: %[[CUR:[^ ]+]] = load i8*, i8** %ap
Stephen Hines176edba2014-12-01 14:53:08 -080068// CHECK: %[[TMP0:[^ ]+]] = ptrtoint i8* %[[CUR]] to i64
69// CHECK: %[[TMP1:[^ ]+]] = add i64 %[[TMP0]], 15
70// CHECK: %[[TMP2:[^ ]+]] = and i64 %[[TMP1]], -16
71// CHECK: %[[ALIGN:[^ ]+]] = inttoptr i64 %[[TMP2]] to i8*
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070072// CHECK: %[[NEXT:[^ ]+]] = getelementptr i8, i8* %[[ALIGN]], i64 16
Stephen Hines176edba2014-12-01 14:53:08 -080073// CHECK: store i8* %[[NEXT]], i8** %ap
74// CHECK: bitcast i8* %[[ALIGN]] to %struct.test2*
Stephen Hinesc568f1e2014-07-21 00:47:37 -070075struct test2 test2va (int x, ...)
76{
77 struct test2 y;
78 va_list ap;
79 va_start(ap, x);
80 y = va_arg (ap, struct test2);
81 va_end(ap);
82 return y;
83}
84
85// CHECK: define void @test3va(%struct.test3* noalias sret %agg.result, i32 signext %x, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070086// CHECK: %[[CUR:[^ ]+]] = load i8*, i8** %ap
Stephen Hines176edba2014-12-01 14:53:08 -080087// CHECK: %[[TMP0:[^ ]+]] = ptrtoint i8* %[[CUR]] to i64
88// CHECK: %[[TMP1:[^ ]+]] = add i64 %[[TMP0]], 15
89// CHECK: %[[TMP2:[^ ]+]] = and i64 %[[TMP1]], -16
90// CHECK: %[[ALIGN:[^ ]+]] = inttoptr i64 %[[TMP2]] to i8*
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070091// CHECK: %[[NEXT:[^ ]+]] = getelementptr i8, i8* %[[ALIGN]], i64 32
Stephen Hines176edba2014-12-01 14:53:08 -080092// CHECK: store i8* %[[NEXT]], i8** %ap
93// CHECK: bitcast i8* %[[ALIGN]] to %struct.test3*
Stephen Hinesc568f1e2014-07-21 00:47:37 -070094struct test3 test3va (int x, ...)
95{
96 struct test3 y;
97 va_list ap;
98 va_start(ap, x);
99 y = va_arg (ap, struct test3);
100 va_end(ap);
101 return y;
102}
103
104// CHECK: define void @test4va(%struct.test4* noalias sret %agg.result, i32 signext %x, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700105// CHECK: %[[CUR:[^ ]+]] = load i8*, i8** %ap
106// CHECK: %[[NEXT:[^ ]+]] = getelementptr i8, i8* %[[CUR]], i64 16
Stephen Hines176edba2014-12-01 14:53:08 -0800107// CHECK: store i8* %[[NEXT]], i8** %ap
108// CHECK: bitcast i8* %[[CUR]] to %struct.test4*
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700109struct test4 test4va (int x, ...)
110{
111 struct test4 y;
112 va_list ap;
113 va_start(ap, x);
114 y = va_arg (ap, struct test4);
115 va_end(ap);
116 return y;
117}
118
119// CHECK: define void @testva_longdouble(%struct.test_longdouble* noalias sret %agg.result, i32 signext %x, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700120// CHECK: %[[CUR:[^ ]+]] = load i8*, i8** %ap
121// CHECK: %[[NEXT:[^ ]+]] = getelementptr i8, i8* %[[CUR]], i64 16
Stephen Hines176edba2014-12-01 14:53:08 -0800122// CHECK: store i8* %[[NEXT]], i8** %ap
123// CHECK: bitcast i8* %[[CUR]] to %struct.test_longdouble*
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700124struct test_longdouble { long double x; };
125struct test_longdouble testva_longdouble (int x, ...)
126{
127 struct test_longdouble y;
128 va_list ap;
129 va_start(ap, x);
130 y = va_arg (ap, struct test_longdouble);
131 va_end(ap);
132 return y;
133}
134
135// CHECK: define void @testva_vector(%struct.test_vector* noalias sret %agg.result, i32 signext %x, ...)
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700136// CHECK: %[[CUR:[^ ]+]] = load i8*, i8** %ap
Stephen Hines176edba2014-12-01 14:53:08 -0800137// CHECK: %[[TMP0:[^ ]+]] = ptrtoint i8* %[[CUR]] to i64
138// CHECK: %[[TMP1:[^ ]+]] = add i64 %[[TMP0]], 15
139// CHECK: %[[TMP2:[^ ]+]] = and i64 %[[TMP1]], -16
140// CHECK: %[[ALIGN:[^ ]+]] = inttoptr i64 %[[TMP2]] to i8*
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700141// CHECK: %[[NEXT:[^ ]+]] = getelementptr i8, i8* %[[ALIGN]], i64 16
Stephen Hines176edba2014-12-01 14:53:08 -0800142// CHECK: store i8* %[[NEXT]], i8** %ap
143// CHECK: bitcast i8* %[[ALIGN]] to %struct.test_vector*
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700144struct test_vector { vector int x; };
145struct test_vector testva_vector (int x, ...)
146{
147 struct test_vector y;
148 va_list ap;
149 va_start(ap, x);
150 y = va_arg (ap, struct test_vector);
151 va_end(ap);
152 return y;
153}
154