1; RUN: opt -mcpu=kryo -loop-simplify -loop-data-prefetch -max-prefetch-iters-ahead=1000 -min-prefetch-stride=16 -S < %s | FileCheck %s
2
3target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
4target triple = "aarch64-unknown-linux-gnu"
5
6%struct._Chv = type { i32, i32, i32, i32, i32, i32, i32*, i32*, double*, %struct._DV, %struct._Chv* }
7%struct._DV = type { i32, i32, i32, double* }
8
9declare double* @f_entries() local_unnamed_addr
10
11define i32 @f(%struct._Chv* %chv, i32 %npivot, i32* %pivotsizes, i32* %sizes) local_unnamed_addr {
12if.end:
13  switch i32 undef, label %sw.default [
14    i32 1, label %sw.epilog
15    i32 3, label %sw.epilog
16    i32 4, label %sw.epilog
17    i32 5, label %sw.epilog
18    i32 6, label %sw.epilog
19    i32 7, label %sw.epilog
20  ]
21
22sw.default:                                       ; preds = %if.end
23  unreachable
24
25sw.epilog:                                        ; preds = %if.end, %if.end, %if.end, %if.end, %if.end, %if.end
26  br label %if.end12
27
28if.end12:                                         ; preds = %sw.epilog
29  %nD13 = getelementptr inbounds %struct._Chv, %struct._Chv* %chv, i64 0, i32 1
30  %0 = load i32, i32* %nD13, align 4
31  %nU15 = getelementptr inbounds %struct._Chv, %struct._Chv* %chv, i64 0, i32 3
32  %1 = load i32, i32* %nU15, align 4
33  %add17 = add i32 %1, %0
34  %call18 = call double* @f_entries()
35  switch i32 undef, label %sw.epilog2454 [
36    i32 3, label %sw.bb213
37  ]
38
39sw.bb213:                                         ; preds = %if.end12
40  switch i32 undef, label %sw.epilog2454 [
41    i32 0, label %sw.bb214
42  ]
43
44sw.bb214:                                         ; preds = %sw.bb213
45  br label %if.then220
46
47if.then220:                                       ; preds = %sw.bb214
48  %type230 = getelementptr inbounds %struct._Chv, %struct._Chv* %chv, i64 0, i32 4
49  %2 = load i32, i32* %type230, align 8
50  br label %if.else319
51
52if.else319:                                       ; preds = %if.then220
53  switch i32 %2, label %sw.epilog2454 [
54    i32 2, label %for.cond372.preheader
55  ]
56
57for.cond372.preheader:                            ; preds = %if.else319
58  %cmp3734342 = icmp sgt i32 %npivot, 0
59  br i1 %cmp3734342, label %for.body374.lr.ph, label %sw.epilog2454
60
61for.body374.lr.ph:                                ; preds = %for.cond372.preheader
62  br label %for.body374
63
64for.body374:                                      ; preds = %for.body374.lr.ph
65  %arrayidx376 = getelementptr inbounds i32, i32* %pivotsizes, i64 0
66  %3 = load i32, i32* %arrayidx376, align 4
67  %add377 = add i32 %3, 0
68  br label %for.body381.lr.ph
69
70for.body381.lr.ph:                                ; preds = %for.body374
71  %cmp3874327 = icmp slt i32 %add377, %add17
72  br i1 %cmp3874327, label %for.body381.us, label %for.body381.preheader
73
74for.body381.preheader:                            ; preds = %for.body381.lr.ph
75  ret i32 undef
76
77for.body381.us:                                   ; preds = %for.cond386.for.end421_crit_edge.us, %for.body381.lr.ph
78  %indvars.iv4991.us = phi i64 [ %indvars.iv.next4992.us, %for.cond386.for.end421_crit_edge.us ], [ undef, %for.body381.lr.ph ]
79  %stride226.54337.us = phi i32 [ %dec423.us, %for.cond386.for.end421_crit_edge.us ], [ %add17, %for.body381.lr.ph ]
80  %kstart225.54336.us = phi i32 [ %add422.us, %for.cond386.for.end421_crit_edge.us ], [ 0, %for.body381.lr.ph ]
81  %4 = trunc i64 %indvars.iv4991.us to i32
82  %5 = xor i32 %4, -1
83  %add382.us = add i32 %add377, %5
84  %sub383.us = add i32 %add382.us, %kstart225.54336.us
85  br label %for.body388.us
86
87; CHECK: for.body388.us:
88; CHECK: call void @llvm.prefetch
89for.body388.us:                                   ; preds = %for.inc418.us, %for.body381.us
90  %kk224.3.in4330.us = phi i32 [ %sub383.us, %for.body381.us ], [ %kk224.3.us, %for.inc418.us ]
91  %jj223.34329.us = phi i32 [ %add377, %for.body381.us ], [ %inc419.us, %for.inc418.us ]
92  %kk224.3.us = add nsw i32 %kk224.3.in4330.us, 1
93  %mul389.us = shl nsw i32 %kk224.3.us, 1
94  %idxprom390.us = sext i32 %mul389.us to i64
95  %arrayidx391.us = getelementptr inbounds double, double* %call18, i64 %idxprom390.us
96  %6 = load double, double* %arrayidx391.us, align 8
97  %call396.us = call double @Zabs(double %6)
98  br label %for.inc418.us
99
100for.inc418.us:                                    ; preds = %for.body388.us
101  %inc419.us = add nsw i32 %jj223.34329.us, 1
102  %cmp387.us = icmp slt i32 %inc419.us, %add17
103  br i1 %cmp387.us, label %for.body388.us, label %for.cond386.for.end421_crit_edge.us
104
105for.cond386.for.end421_crit_edge.us:              ; preds = %for.inc418.us
106  %add422.us = add nsw i32 %kstart225.54336.us, %stride226.54337.us
107  %dec423.us = add nsw i32 %stride226.54337.us, -1
108  %indvars.iv.next4992.us = add nsw i64 %indvars.iv4991.us, 1
109  br label %for.body381.us
110
111sw.epilog2454:                                    ; preds = %for.cond372.preheader, %if.else319, %sw.bb213, %if.end12
112  ret i32 0
113}
114
115declare double @llvm.fabs.f64(double)
116declare dso_local double @Zabs(double) local_unnamed_addr
117declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
118
119