1; RUN: llc -march=hexagon -mcpu=hexagonv62  -mtriple=hexagon-unknown-linux-musl -O0 < %s | FileCheck %s
2
3; CHECK-LABEL: foo:
4
5; Check Function prologue.
6; Note. All register numbers and offset are fixed.
7; Hence, no need of regular expression.
8
9; CHECK: r29 = add(r29,#-24)
10; CHECK: r7:6 = memd(r29+#24)
11; CHECK: memd(r29+#0) = r7:6
12; CHECK: r7:6 = memd(r29+#32)
13; CHECK: memd(r29+#8) = r7:6
14; CHECK: r7:6 = memd(r29+#40)
15; CHECK: memd(r29+#16) = r7:6
16; CHECK: memw(r29+#28) = r1
17; CHECK: memw(r29+#32) = r2
18; CHECK: memw(r29+#36) = r3
19; CHECK: memw(r29+#40) = r4
20; CHECK: memw(r29+#44) = r5
21; CHECK: r29 = add(r29,#24)
22
23%struct.AAA = type { i32, i32, i32, i32 }
24%struct.BBB = type { i8, i64, i32 }
25%struct.__va_list_tag = type { i8*, i8*, i8* }
26
27@aaa = global %struct.AAA { i32 100, i32 200, i32 300, i32 400 }, align 4
28@ddd = global { i8, i64, i32, [4 x i8] } { i8 1, i64 1000000, i32 5, [4 x i8] undef }, align 8
29@.str = private unnamed_addr constant [13 x i8] c"result = %d\0A\00", align 1
30
31; Function Attrs: nounwind
32define i32 @foo(i32 %xx, %struct.BBB* byval(%struct.BBB) align 8 %eee, ...) #0 {
33entry:
34  %xx.addr = alloca i32, align 4
35  %ap = alloca [1 x %struct.__va_list_tag], align 8
36  %d = alloca i32, align 4
37  %k = alloca i64, align 8
38  %ret = alloca i32, align 4
39  %bbb = alloca %struct.AAA, align 4
40  store i32 %xx, i32* %xx.addr, align 4
41  store i32 0, i32* %ret, align 4
42  %x = getelementptr inbounds %struct.BBB, %struct.BBB* %eee, i32 0, i32 0
43  %0 = load i8, i8* %x, align 1
44  %tobool = trunc i8 %0 to i1
45  br i1 %tobool, label %if.then, label %if.end
46
47if.then:                                          ; preds = %entry
48  store i32 1, i32* %ret, align 4
49  br label %if.end
50
51if.end:                                           ; preds = %if.then, %entry
52  %arraydecay = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
53  %arraydecay1 = bitcast %struct.__va_list_tag* %arraydecay to i8*
54  call void @llvm.va_start(i8* %arraydecay1)
55  %arraydecay2 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
56  br label %vaarg.maybe_reg
57
58vaarg.maybe_reg:                                  ; preds = %if.end
59  %__current_saved_reg_area_pointer_p = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay2, i32 0, i32 0
60  %__current_saved_reg_area_pointer = load i8*, i8** %__current_saved_reg_area_pointer_p
61  %__saved_reg_area_end_pointer_p = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay2, i32 0, i32 1
62  %__saved_reg_area_end_pointer = load i8*, i8** %__saved_reg_area_end_pointer_p
63  %1 = ptrtoint i8* %__current_saved_reg_area_pointer to i32
64  %align_current_saved_reg_area_pointer = add i32 %1, 7
65  %align_current_saved_reg_area_pointer3 = and i32 %align_current_saved_reg_area_pointer, -8
66  %align_current_saved_reg_area_pointer4 = inttoptr i32 %align_current_saved_reg_area_pointer3 to i8*
67  %__new_saved_reg_area_pointer = getelementptr i8, i8* %align_current_saved_reg_area_pointer4, i32 8
68  %2 = icmp sgt i8* %__new_saved_reg_area_pointer, %__saved_reg_area_end_pointer
69  br i1 %2, label %vaarg.on_stack, label %vaarg.in_reg
70
71vaarg.in_reg:                                     ; preds = %vaarg.maybe_reg
72  %3 = bitcast i8* %align_current_saved_reg_area_pointer4 to i64*
73  store i8* %__new_saved_reg_area_pointer, i8** %__current_saved_reg_area_pointer_p
74  br label %vaarg.end
75
76vaarg.on_stack:                                   ; preds = %vaarg.maybe_reg
77  %__overflow_area_pointer_p = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay2, i32 0, i32 2
78  %__overflow_area_pointer = load i8*, i8** %__overflow_area_pointer_p
79  %4 = ptrtoint i8* %__overflow_area_pointer to i32
80  %align_overflow_area_pointer = add i32 %4, 7
81  %align_overflow_area_pointer5 = and i32 %align_overflow_area_pointer, -8
82  %align_overflow_area_pointer6 = inttoptr i32 %align_overflow_area_pointer5 to i8*
83  %__overflow_area_pointer.next = getelementptr i8, i8* %align_overflow_area_pointer6, i32 8
84  store i8* %__overflow_area_pointer.next, i8** %__overflow_area_pointer_p
85  store i8* %__overflow_area_pointer.next, i8** %__current_saved_reg_area_pointer_p
86  %5 = bitcast i8* %align_overflow_area_pointer6 to i64*
87  br label %vaarg.end
88
89vaarg.end:                                        ; preds = %vaarg.on_stack, %vaarg.in_reg
90  %vaarg.addr = phi i64* [ %3, %vaarg.in_reg ], [ %5, %vaarg.on_stack ]
91  %6 = load i64, i64* %vaarg.addr
92  store i64 %6, i64* %k, align 8
93  %7 = load i64, i64* %k, align 8
94  %conv = trunc i64 %7 to i32
95  %div = sdiv i32 %conv, 1000
96  %8 = load i32, i32* %ret, align 4
97  %add = add nsw i32 %8, %div
98  store i32 %add, i32* %ret, align 4
99  %arraydecay7 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
100  %__overflow_area_pointer_p8 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay7, i32 0, i32 2
101  %__overflow_area_pointer9 = load i8*, i8** %__overflow_area_pointer_p8
102  %9 = bitcast i8* %__overflow_area_pointer9 to %struct.AAA*
103  %__overflow_area_pointer.next10 = getelementptr i8, i8* %__overflow_area_pointer9, i32 16
104  store i8* %__overflow_area_pointer.next10, i8** %__overflow_area_pointer_p8
105  %10 = bitcast %struct.AAA* %bbb to i8*
106  %11 = bitcast %struct.AAA* %9 to i8*
107  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %10, i8* %11, i32 16, i32 4, i1 false)
108  %d11 = getelementptr inbounds %struct.AAA, %struct.AAA* %bbb, i32 0, i32 3
109  %12 = load i32, i32* %d11, align 4
110  %13 = load i32, i32* %ret, align 4
111  %add12 = add nsw i32 %13, %12
112  store i32 %add12, i32* %ret, align 4
113  %arraydecay13 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
114  br label %vaarg.maybe_reg14
115
116vaarg.maybe_reg14:                                ; preds = %vaarg.end
117  %__current_saved_reg_area_pointer_p15 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay13, i32 0, i32 0
118  %__current_saved_reg_area_pointer16 = load i8*, i8** %__current_saved_reg_area_pointer_p15
119  %__saved_reg_area_end_pointer_p17 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay13, i32 0, i32 1
120  %__saved_reg_area_end_pointer18 = load i8*, i8** %__saved_reg_area_end_pointer_p17
121  %__new_saved_reg_area_pointer19 = getelementptr i8, i8* %__current_saved_reg_area_pointer16, i32 4
122  %14 = icmp sgt i8* %__new_saved_reg_area_pointer19, %__saved_reg_area_end_pointer18
123  br i1 %14, label %vaarg.on_stack21, label %vaarg.in_reg20
124
125vaarg.in_reg20:                                   ; preds = %vaarg.maybe_reg14
126  %15 = bitcast i8* %__current_saved_reg_area_pointer16 to i32*
127  store i8* %__new_saved_reg_area_pointer19, i8** %__current_saved_reg_area_pointer_p15
128  br label %vaarg.end25
129
130vaarg.on_stack21:                                 ; preds = %vaarg.maybe_reg14
131  %__overflow_area_pointer_p22 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay13, i32 0, i32 2
132  %__overflow_area_pointer23 = load i8*, i8** %__overflow_area_pointer_p22
133  %__overflow_area_pointer.next24 = getelementptr i8, i8* %__overflow_area_pointer23, i32 4
134  store i8* %__overflow_area_pointer.next24, i8** %__overflow_area_pointer_p22
135  store i8* %__overflow_area_pointer.next24, i8** %__current_saved_reg_area_pointer_p15
136  %16 = bitcast i8* %__overflow_area_pointer23 to i32*
137  br label %vaarg.end25
138
139vaarg.end25:                                      ; preds = %vaarg.on_stack21, %vaarg.in_reg20
140  %vaarg.addr26 = phi i32* [ %15, %vaarg.in_reg20 ], [ %16, %vaarg.on_stack21 ]
141  %17 = load i32, i32* %vaarg.addr26
142  store i32 %17, i32* %d, align 4
143  %18 = load i32, i32* %d, align 4
144  %19 = load i32, i32* %ret, align 4
145  %add27 = add nsw i32 %19, %18
146  store i32 %add27, i32* %ret, align 4
147  %arraydecay28 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
148  %arraydecay2829 = bitcast %struct.__va_list_tag* %arraydecay28 to i8*
149  call void @llvm.va_end(i8* %arraydecay2829)
150  %20 = load i32, i32* %ret, align 4
151  ret i32 %20
152}
153
154; Function Attrs: nounwind
155declare void @llvm.va_start(i8*) #1
156
157; Function Attrs: nounwind
158declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1) #1
159
160; Function Attrs: nounwind
161declare void @llvm.va_end(i8*) #1
162
163; Function Attrs: nounwind
164define i32 @main() #0 {
165entry:
166  %retval = alloca i32, align 4
167  %x = alloca i32, align 4
168  %m = alloca i64, align 8
169  store i32 0, i32* %retval
170  store i64 1000000, i64* %m, align 8
171  %0 = load i64, i64* %m, align 8
172  %call = call i32 (i32, %struct.BBB*, ...) @foo(i32 1, %struct.BBB* byval(%struct.BBB) align 8 bitcast ({ i8, i64, i32, [4 x i8] }* @ddd to %struct.BBB*), i64 %0, %struct.AAA* byval(%struct.AAA) align 4 @aaa, i32 4)
173  store i32 %call, i32* %x, align 4
174  %1 = load i32, i32* %x, align 4
175  %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i32 %1)
176  %2 = load i32, i32* %x, align 4
177  ret i32 %2
178}
179
180declare i32 @printf(i8*, ...) #2
181
182attributes #1 = { nounwind }
183
184!llvm.ident = !{!0}
185
186!0 = !{!"Clang 3.1"}
187