1; RUN: llc -march=hexagon < %s | FileCheck %s
2; CHECK: f1
3
4target triple = "hexagon"
5
6%s.0 = type { i32 }
7
8@g0 = internal unnamed_addr global %s.0* null, section ".data.............", align 4
9@g1 = internal global i32 0, section ".data.............", align 4
10
11; Function Attrs: nounwind
12define %s.0* @f0(i32* %a0) #0 {
13b0:
14  %v0 = getelementptr inbounds i32, i32* %a0, i32 -1
15  %v1 = load i32, i32* %v0, align 4
16  %v2 = and i32 %v1, -3
17  store i32 %v2, i32* %v0, align 4
18  %v3 = getelementptr inbounds i32, i32* %a0, i32 -2
19  %v4 = load i32, i32* %v3, align 4
20  %v5 = lshr i32 %v4, 2
21  %v6 = xor i32 %v5, -1
22  %v7 = getelementptr inbounds i32, i32* %a0, i32 %v6
23  %v8 = lshr i32 %v1, 2
24  %v9 = add i32 %v8, -1
25  %v10 = getelementptr inbounds i32, i32* %a0, i32 %v9
26  %v11 = load i32, i32* %v10, align 4
27  %v12 = lshr i32 %v11, 2
28  %v13 = icmp eq i32 %v12, 0
29  br i1 %v13, label %b3, label %b1
30
31b1:                                               ; preds = %b0
32  %v14 = add i32 %v12, %v9
33  %v15 = getelementptr inbounds i32, i32* %a0, i32 %v14
34  %v16 = load i32, i32* %v15, align 4
35  %v17 = and i32 %v16, 1
36  %v18 = icmp eq i32 %v17, 0
37  br i1 %v18, label %b3, label %b2
38
39b2:                                               ; preds = %b1
40  %v19 = add nsw i32 %v12, %v8
41  %v20 = shl i32 %v19, 2
42  %v21 = and i32 %v1, 1
43  %v22 = or i32 %v20, %v21
44  store i32 %v22, i32* %v0, align 4
45  br label %b3
46
47b3:                                               ; preds = %b2, %b1, %b0
48  %v23 = phi i32 [ %v2, %b1 ], [ %v2, %b0 ], [ %v22, %b2 ]
49  %v24 = and i32 %v23, 1
50  %v25 = icmp eq i32 %v24, 0
51  br i1 %v25, label %b5, label %b4
52
53b4:                                               ; preds = %b3
54  %v26 = load i32, i32* %v7, align 4
55  %v27 = and i32 %v26, -4
56  %v28 = add i32 %v27, %v23
57  %v29 = and i32 %v28, -4
58  %v30 = and i32 %v26, 3
59  %v31 = or i32 %v29, %v30
60  store i32 %v31, i32* %v7, align 4
61  br label %b5
62
63b5:                                               ; preds = %b4, %b3
64  %v32 = phi i32 [ %v31, %b4 ], [ %v23, %b3 ]
65  %v33 = phi i32* [ %v7, %b4 ], [ %v0, %b3 ]
66  %v34 = bitcast i32* %v33 to %s.0*
67  %v35 = lshr i32 %v32, 2
68  %v36 = add i32 %v35, -1
69  %v37 = getelementptr inbounds %s.0, %s.0* %v34, i32 %v36, i32 0
70  %v38 = load i32, i32* %v37, align 4
71  %v39 = shl nuw i32 %v35, 2
72  %v40 = and i32 %v38, 3
73  %v41 = or i32 %v40, %v39
74  store i32 %v41, i32* %v37, align 4
75  %v42 = load i32, i32* %v33, align 4
76  %v43 = lshr i32 %v42, 2
77  %v44 = getelementptr inbounds %s.0, %s.0* %v34, i32 %v43, i32 0
78  %v45 = load i32, i32* %v44, align 4
79  %v46 = or i32 %v45, 1
80  store i32 %v46, i32* %v44, align 4
81  ret %s.0* %v34
82}
83
84; Function Attrs: nounwind
85define i64 @f1(i32 %a0) #0 {
86b0:
87  %v0 = load %s.0*, %s.0** @g0, align 4, !tbaa !0
88  %v1 = getelementptr inbounds %s.0, %s.0* %v0, i32 7
89  tail call void @f2(i32* @g1) #0
90  br label %b1
91
92b1:                                               ; preds = %b5, %b0
93  %v2 = phi %s.0* [ %v1, %b0 ], [ %v20, %b5 ]
94  %v3 = getelementptr inbounds %s.0, %s.0* %v2, i32 0, i32 0
95  %v4 = load i32, i32* %v3, align 4
96  %v5 = and i32 %v4, 2
97  %v6 = icmp eq i32 %v5, 0
98  br i1 %v6, label %b3, label %b2
99
100b2:                                               ; preds = %b1
101  tail call fastcc void @f8()
102  %v7 = getelementptr inbounds %s.0, %s.0* %v2, i32 1, i32 0
103  %v8 = tail call %s.0* @f0(i32* %v7)
104  tail call fastcc void @f7()
105  br label %b3
106
107b3:                                               ; preds = %b2, %b1
108  %v9 = phi %s.0* [ %v8, %b2 ], [ %v2, %b1 ]
109  %v10 = getelementptr inbounds %s.0, %s.0* %v9, i32 0, i32 0
110  %v11 = load i32, i32* %v10, align 4
111  %v12 = lshr i32 %v11, 2
112  %v13 = getelementptr inbounds %s.0, %s.0* %v9, i32 %v12, i32 0
113  %v14 = load i32, i32* %v13, align 4
114  %v15 = and i32 %v14, 1
115  %v16 = icmp eq i32 %v15, 0
116  br i1 %v16, label %b5, label %b4
117
118b4:                                               ; preds = %b3
119  %v17 = mul i32 %v12, 4
120  %v18 = add i32 %v17, -4
121  %v19 = icmp ult i32 %v18, %a0
122  br i1 %v19, label %b5, label %b7
123
124b5:                                               ; preds = %b4, %b3
125  %v20 = getelementptr inbounds %s.0, %s.0* %v9, i32 %v12
126  %v21 = icmp ult i32 %v14, 4
127  br i1 %v21, label %b6, label %b1
128
129b6:                                               ; preds = %b5
130  tail call fastcc void @f3()
131  br label %b11
132
133b7:                                               ; preds = %b4
134  %v22 = add i32 %a0, 4
135  %v23 = lshr i32 %v22, 2
136  %v24 = add i32 %v23, 8
137  %v25 = lshr i32 %v24, 3
138  %v26 = mul nsw i32 %v25, 8
139  %v27 = sub nsw i32 %v12, %v26
140  %v28 = icmp sgt i32 %v27, 7
141  br i1 %v28, label %b8, label %b9
142
143b8:                                               ; preds = %b7
144  %v29 = getelementptr inbounds %s.0, %s.0* %v9, i32 %v26, i32 0
145  %v30 = shl i32 %v27, 2
146  store i32 %v30, i32* %v29, align 4
147  %v31 = load i32, i32* %v10, align 4
148  %v32 = lshr i32 %v31, 2
149  %v33 = add i32 %v32, -1
150  %v34 = getelementptr inbounds %s.0, %s.0* %v9, i32 %v33, i32 0
151  %v35 = load i32, i32* %v34, align 4
152  %v36 = and i32 %v35, 3
153  %v37 = or i32 %v36, %v30
154  store i32 %v37, i32* %v34, align 4
155  %v38 = load i32, i32* %v10, align 4
156  %v39 = mul i32 %v25, 32
157  %v40 = and i32 %v38, 3
158  %v41 = or i32 %v40, %v39
159  store i32 %v41, i32* %v10, align 4
160  br label %b10
161
162b9:                                               ; preds = %b7
163  %v42 = and i32 %v14, -2
164  store i32 %v42, i32* %v13, align 4
165  br label %b10
166
167b10:                                              ; preds = %b9, %b8
168  tail call fastcc void @f3()
169  %v43 = getelementptr inbounds %s.0, %s.0* %v9, i32 1
170  %v44 = load i32, i32* %v10, align 4
171  %v45 = lshr i32 %v44, 2
172  %v46 = mul i32 %v45, 4
173  %v47 = add i32 %v46, -4
174  %v48 = ptrtoint %s.0* %v43 to i32
175  %v49 = zext i32 %v47 to i64
176  %v50 = shl nuw i64 %v49, 32
177  %v51 = zext i32 %v48 to i64
178  br label %b11
179
180b11:                                              ; preds = %b10, %b6
181  %v52 = phi i64 [ 0, %b6 ], [ %v51, %b10 ]
182  %v53 = phi i64 [ 0, %b6 ], [ %v50, %b10 ]
183  %v54 = or i64 %v53, %v52
184  ret i64 %v54
185}
186
187declare void @f2(i32*) #0
188
189; Function Attrs: inlinehint nounwind
190define internal fastcc void @f3() #1 {
191b0:
192  store i32 0, i32* @g1, align 4, !tbaa !4
193  ret void
194}
195
196; Function Attrs: nounwind
197define void @f4(i32* nocapture %a0) #0 {
198b0:
199  %v0 = getelementptr inbounds i32, i32* %a0, i32 -1
200  tail call void @f2(i32* @g1) #0
201  %v1 = load i32, i32* %v0, align 4
202  %v2 = or i32 %v1, 2
203  store i32 %v2, i32* %v0, align 4
204  tail call fastcc void @f3()
205  ret void
206}
207
208; Function Attrs: nounwind
209define %s.0* @f5(i32* %a0) #0 {
210b0:
211  tail call void @f2(i32* @g1) #0
212  %v0 = tail call %s.0* @f0(i32* %a0)
213  tail call fastcc void @f3()
214  ret %s.0* %v0
215}
216
217; Function Attrs: nounwind
218define void @f6(%s.0* %a0, i32 %a1) #0 {
219b0:
220  %v0 = getelementptr inbounds %s.0, %s.0* %a0, i32 7, i32 0
221  %v1 = mul i32 %a1, 4
222  %v2 = add i32 %v1, -32
223  store i32 %v2, i32* %v0, align 4
224  %v3 = add i32 %a1, -1
225  %v4 = getelementptr inbounds %s.0, %s.0* %a0, i32 %v3, i32 0
226  store i32 1, i32* %v4, align 4
227  store i32 0, i32* @g1, align 4, !tbaa !4
228  store %s.0* %a0, %s.0** @g0, align 4
229  ret void
230}
231
232; Function Attrs: inlinehint nounwind
233define internal fastcc void @f7() #1 {
234b0:
235  tail call void asm sideeffect " nop", "~{memory}"() #0, !srcloc !6
236  ret void
237}
238
239; Function Attrs: inlinehint nounwind
240define internal fastcc void @f8() #1 {
241b0:
242  tail call void asm sideeffect " nop", "~{memory}"() #0, !srcloc !7
243  ret void
244}
245
246attributes #0 = { nounwind }
247attributes #1 = { inlinehint nounwind }
248
249!0 = !{!1, !1, i64 0}
250!1 = !{!"any pointer", !2}
251!2 = !{!"omnipotent char", !3}
252!3 = !{!"Simple C/C++ TBAA"}
253!4 = !{!5, !5, i64 0}
254!5 = !{!"int", !2}
255!6 = !{i32 782713}
256!7 = !{i32 782625}
257