1 ; RUN: llc -march=hexagon -mcpu=hexagonv62 -mtriple=hexagon-unknown-linux-musl -O0 < %s | FileCheck %s
5 ; Check Function prologue.
6 ; Note. All register numbers and offset are fixed.
7 ; Hence, no need of regular expression.
9 ; CHECK: r29 = add(r29,#-8)
10 ; CHECK: memw(r29+#4) = r5
11 ; CHECK: r29 = add(r29,#8)
13 %struct.AAA = type { i32, i32, i32, i32 }
14 %struct.__va_list_tag = type { i8*, i8*, i8* }
16 @aaa = global %struct.AAA { i32 100, i32 200, i32 300, i32 400 }, align 4
17 @.str = private unnamed_addr constant [13 x i8] c"result = %d\0A\00", align 1
19 ; Function Attrs: nounwind
20 define i32 @foo(i32 %xx, i32 %a, i32 %b, i32 %c, i32 %x, ...) #0 {
22 %xx.addr = alloca i32, align 4
23 %a.addr = alloca i32, align 4
24 %b.addr = alloca i32, align 4
25 %c.addr = alloca i32, align 4
26 %x.addr = alloca i32, align 4
27 %ap = alloca [1 x %struct.__va_list_tag], align 8
28 %d = alloca i32, align 4
29 %ret = alloca i32, align 4
30 %bbb = alloca %struct.AAA, align 4
31 store i32 %xx, i32* %xx.addr, align 4
32 store i32 %a, i32* %a.addr, align 4
33 store i32 %b, i32* %b.addr, align 4
34 store i32 %c, i32* %c.addr, align 4
35 store i32 %x, i32* %x.addr, align 4
36 store i32 0, i32* %ret, align 4
37 %arraydecay = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
38 %arraydecay1 = bitcast %struct.__va_list_tag* %arraydecay to i8*
39 call void @llvm.va_start(i8* %arraydecay1)
40 %arraydecay2 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
41 br label %vaarg.maybe_reg
43 vaarg.maybe_reg: ; preds = %entry
44 %__current_saved_reg_area_pointer_p = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay2, i32 0, i32 0
45 %__current_saved_reg_area_pointer = load i8*, i8** %__current_saved_reg_area_pointer_p
46 %__saved_reg_area_end_pointer_p = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay2, i32 0, i32 1
47 %__saved_reg_area_end_pointer = load i8*, i8** %__saved_reg_area_end_pointer_p
48 %0 = ptrtoint i8* %__current_saved_reg_area_pointer to i32
49 %align_current_saved_reg_area_pointer = add i32 %0, 7
50 %align_current_saved_reg_area_pointer3 = and i32 %align_current_saved_reg_area_pointer, -8
51 %align_current_saved_reg_area_pointer4 = inttoptr i32 %align_current_saved_reg_area_pointer3 to i8*
52 %__new_saved_reg_area_pointer = getelementptr i8, i8* %align_current_saved_reg_area_pointer4, i32 8
53 %1 = icmp sgt i8* %__new_saved_reg_area_pointer, %__saved_reg_area_end_pointer
54 br i1 %1, label %vaarg.on_stack, label %vaarg.in_reg
56 vaarg.in_reg: ; preds = %vaarg.maybe_reg
57 %2 = bitcast i8* %align_current_saved_reg_area_pointer4 to i64*
58 store i8* %__new_saved_reg_area_pointer, i8** %__current_saved_reg_area_pointer_p
61 vaarg.on_stack: ; preds = %vaarg.maybe_reg
62 %__overflow_area_pointer_p = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay2, i32 0, i32 2
63 %__overflow_area_pointer = load i8*, i8** %__overflow_area_pointer_p
64 %3 = ptrtoint i8* %__overflow_area_pointer to i32
65 %align_overflow_area_pointer = add i32 %3, 7
66 %align_overflow_area_pointer5 = and i32 %align_overflow_area_pointer, -8
67 %align_overflow_area_pointer6 = inttoptr i32 %align_overflow_area_pointer5 to i8*
68 %__overflow_area_pointer.next = getelementptr i8, i8* %align_overflow_area_pointer6, i32 8
69 store i8* %__overflow_area_pointer.next, i8** %__overflow_area_pointer_p
70 store i8* %__overflow_area_pointer.next, i8** %__current_saved_reg_area_pointer_p
71 %4 = bitcast i8* %align_overflow_area_pointer6 to i64*
74 vaarg.end: ; preds = %vaarg.on_stack, %vaarg.in_reg
75 %vaarg.addr = phi i64* [ %2, %vaarg.in_reg ], [ %4, %vaarg.on_stack ]
76 %5 = load i64, i64* %vaarg.addr
77 %conv = trunc i64 %5 to i32
78 store i32 %conv, i32* %d, align 4
79 %6 = load i32, i32* %d, align 4
80 %7 = load i32, i32* %ret, align 4
81 %add = add nsw i32 %7, %6
82 store i32 %add, i32* %ret, align 4
83 %arraydecay7 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
84 %__overflow_area_pointer_p8 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay7, i32 0, i32 2
85 %__overflow_area_pointer9 = load i8*, i8** %__overflow_area_pointer_p8
86 %8 = bitcast i8* %__overflow_area_pointer9 to %struct.AAA*
87 %__overflow_area_pointer.next10 = getelementptr i8, i8* %__overflow_area_pointer9, i32 16
88 store i8* %__overflow_area_pointer.next10, i8** %__overflow_area_pointer_p8
89 %9 = bitcast %struct.AAA* %bbb to i8*
90 %10 = bitcast %struct.AAA* %8 to i8*
91 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %9, i8* %10, i32 16, i32 4, i1 false)
92 %d11 = getelementptr inbounds %struct.AAA, %struct.AAA* %bbb, i32 0, i32 3
93 %11 = load i32, i32* %d11, align 4
94 %12 = load i32, i32* %ret, align 4
95 %add12 = add nsw i32 %12, %11
96 store i32 %add12, i32* %ret, align 4
97 %arraydecay13 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
98 br label %vaarg.maybe_reg14
100 vaarg.maybe_reg14: ; preds = %vaarg.end
101 %__current_saved_reg_area_pointer_p15 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay13, i32 0, i32 0
102 %__current_saved_reg_area_pointer16 = load i8*, i8** %__current_saved_reg_area_pointer_p15
103 %__saved_reg_area_end_pointer_p17 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay13, i32 0, i32 1
104 %__saved_reg_area_end_pointer18 = load i8*, i8** %__saved_reg_area_end_pointer_p17
105 %__new_saved_reg_area_pointer19 = getelementptr i8, i8* %__current_saved_reg_area_pointer16, i32 4
106 %13 = icmp sgt i8* %__new_saved_reg_area_pointer19, %__saved_reg_area_end_pointer18
107 br i1 %13, label %vaarg.on_stack21, label %vaarg.in_reg20
109 vaarg.in_reg20: ; preds = %vaarg.maybe_reg14
110 %14 = bitcast i8* %__current_saved_reg_area_pointer16 to i32*
111 store i8* %__new_saved_reg_area_pointer19, i8** %__current_saved_reg_area_pointer_p15
112 br label %vaarg.end25
114 vaarg.on_stack21: ; preds = %vaarg.maybe_reg14
115 %__overflow_area_pointer_p22 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay13, i32 0, i32 2
116 %__overflow_area_pointer23 = load i8*, i8** %__overflow_area_pointer_p22
117 %__overflow_area_pointer.next24 = getelementptr i8, i8* %__overflow_area_pointer23, i32 4
118 store i8* %__overflow_area_pointer.next24, i8** %__overflow_area_pointer_p22
119 store i8* %__overflow_area_pointer.next24, i8** %__current_saved_reg_area_pointer_p15
120 %15 = bitcast i8* %__overflow_area_pointer23 to i32*
121 br label %vaarg.end25
123 vaarg.end25: ; preds = %vaarg.on_stack21, %vaarg.in_reg20
124 %vaarg.addr26 = phi i32* [ %14, %vaarg.in_reg20 ], [ %15, %vaarg.on_stack21 ]
125 %16 = load i32, i32* %vaarg.addr26
126 store i32 %16, i32* %d, align 4
127 %17 = load i32, i32* %d, align 4
128 %18 = load i32, i32* %ret, align 4
129 %add27 = add nsw i32 %18, %17
130 store i32 %add27, i32* %ret, align 4
131 %arraydecay28 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
132 br label %vaarg.maybe_reg29
134 vaarg.maybe_reg29: ; preds = %vaarg.end25
135 %__current_saved_reg_area_pointer_p30 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay28, i32 0, i32 0
136 %__current_saved_reg_area_pointer31 = load i8*, i8** %__current_saved_reg_area_pointer_p30
137 %__saved_reg_area_end_pointer_p32 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay28, i32 0, i32 1
138 %__saved_reg_area_end_pointer33 = load i8*, i8** %__saved_reg_area_end_pointer_p32
139 %19 = ptrtoint i8* %__current_saved_reg_area_pointer31 to i32
140 %align_current_saved_reg_area_pointer34 = add i32 %19, 7
141 %align_current_saved_reg_area_pointer35 = and i32 %align_current_saved_reg_area_pointer34, -8
142 %align_current_saved_reg_area_pointer36 = inttoptr i32 %align_current_saved_reg_area_pointer35 to i8*
143 %__new_saved_reg_area_pointer37 = getelementptr i8, i8* %align_current_saved_reg_area_pointer36, i32 8
144 %20 = icmp sgt i8* %__new_saved_reg_area_pointer37, %__saved_reg_area_end_pointer33
145 br i1 %20, label %vaarg.on_stack39, label %vaarg.in_reg38
147 vaarg.in_reg38: ; preds = %vaarg.maybe_reg29
148 %21 = bitcast i8* %align_current_saved_reg_area_pointer36 to i64*
149 store i8* %__new_saved_reg_area_pointer37, i8** %__current_saved_reg_area_pointer_p30
150 br label %vaarg.end46
152 vaarg.on_stack39: ; preds = %vaarg.maybe_reg29
153 %__overflow_area_pointer_p40 = getelementptr inbounds %struct.__va_list_tag, %struct.__va_list_tag* %arraydecay28, i32 0, i32 2
154 %__overflow_area_pointer41 = load i8*, i8** %__overflow_area_pointer_p40
155 %22 = ptrtoint i8* %__overflow_area_pointer41 to i32
156 %align_overflow_area_pointer42 = add i32 %22, 7
157 %align_overflow_area_pointer43 = and i32 %align_overflow_area_pointer42, -8
158 %align_overflow_area_pointer44 = inttoptr i32 %align_overflow_area_pointer43 to i8*
159 %__overflow_area_pointer.next45 = getelementptr i8, i8* %align_overflow_area_pointer44, i32 8
160 store i8* %__overflow_area_pointer.next45, i8** %__overflow_area_pointer_p40
161 store i8* %__overflow_area_pointer.next45, i8** %__current_saved_reg_area_pointer_p30
162 %23 = bitcast i8* %align_overflow_area_pointer44 to i64*
163 br label %vaarg.end46
165 vaarg.end46: ; preds = %vaarg.on_stack39, %vaarg.in_reg38
166 %vaarg.addr47 = phi i64* [ %21, %vaarg.in_reg38 ], [ %23, %vaarg.on_stack39 ]
167 %24 = load i64, i64* %vaarg.addr47
168 %conv48 = trunc i64 %24 to i32
169 store i32 %conv48, i32* %d, align 4
170 %25 = load i32, i32* %d, align 4
171 %26 = load i32, i32* %ret, align 4
172 %add49 = add nsw i32 %26, %25
173 store i32 %add49, i32* %ret, align 4
174 %arraydecay50 = getelementptr inbounds [1 x %struct.__va_list_tag], [1 x %struct.__va_list_tag]* %ap, i32 0, i32 0
175 %arraydecay5051 = bitcast %struct.__va_list_tag* %arraydecay50 to i8*
176 call void @llvm.va_end(i8* %arraydecay5051)
177 %27 = load i32, i32* %ret, align 4
181 ; Function Attrs: nounwind
182 declare void @llvm.va_start(i8*) #1
184 ; Function Attrs: nounwind
185 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1) #1
187 ; Function Attrs: nounwind
188 declare void @llvm.va_end(i8*) #1
190 ; Function Attrs: nounwind
191 define i32 @main() #0 {
193 %retval = alloca i32, align 4
194 %x = alloca i32, align 4
195 %y = alloca i64, align 8
196 store i32 0, i32* %retval
197 store i64 1000000, i64* %y, align 8
198 %0 = load i64, i64* %y, align 8
199 %1 = load i64, i64* %y, align 8
200 %call = call i32 (i32, i32, i32, i32, i32, ...) @foo(i32 1, i32 2, i32 3, i32 4, i32 5, i64 %0, %struct.AAA* byval(%struct.AAA) align 4 @aaa, i32 4, i64 %1)
201 store i32 %call, i32* %x, align 4
202 %2 = load i32, i32* %x, align 4
203 %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i32 %2)
204 %3 = load i32, i32* %x, align 4
208 declare i32 @printf(i8*, ...) #2
210 attributes #0 = { nounwind }