xref: /llvm-project/llvm/test/Analysis/LoopCacheAnalysis/PowerPC/compute-cost.ll (revision 670259466b238176ac302c8dedf806d2b2be7e0c)
1; RUN: opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck %s
2
3target datalayout = "e-m:e-i64:64-n32:64"
4target triple = "powerpc64le-unknown-linux-gnu"
5
6; Check IndexedReference::computeRefCost can handle type differences between
7; Stride and TripCount
8
9; CHECK: Loop 'for.cond' has cost = 64
10
11%struct._Handleitem = type { ptr }
12
13define void @handle_to_ptr(ptr %blocks) {
14; Preheader:
15entry:
16  br label %for.cond
17
18; Loop:
19for.cond:                                         ; preds = %for.body, %entry
20  %i.0 = phi i32 [ 1, %entry ], [ %inc, %for.body ]
21  %cmp = icmp ult i32 %i.0, 1024
22  br i1 %cmp, label %for.body, label %for.end
23
24for.body:                                         ; preds = %for.cond
25  %idxprom = zext i32 %i.0 to i64
26  %arrayidx = getelementptr inbounds ptr, ptr %blocks, i64 %idxprom
27  store ptr null, ptr %arrayidx, align 8
28  %inc = add nuw nsw i32 %i.0, 1
29  br label %for.cond
30
31; Exit blocks
32for.end:                                          ; preds = %for.cond
33  ret void
34}
35
36; Check IndexedReference::computeRefCost can handle type differences between
37; Coeff and ElemSize.
38
39; CHECK: Loop 'for.cond' has cost = 100000000
40; CHECK: Loop 'for.cond1' has cost = 1000000
41; CHECK: Loop 'for.cond5' has cost = 40000
42
43@data = external dso_local global [2 x [4 x [18 x i32]]], align 1
44
45define dso_local void @handle_to_ptr_2(i1 %b0, i1 %b1, i1 %b2) {
46entry:
47  br label %for.cond
48
49for.cond:
50  %i.0 = phi i16 [ 0, %entry ], [ %inc18, %for.inc17 ]
51  %idxprom = zext i16 %i.0 to i32
52  br i1 %b2, label %for.end19, label %for.cond1
53
54for.cond1:
55  %j.0 = phi i16 [ %inc15, %for.inc14 ], [ 0, %for.cond ]
56  br i1 %b1, label %for.inc17, label %for.cond5.preheader
57
58for.cond5.preheader:
59  %idxprom10 = zext i16 %j.0 to i32
60  br label %for.cond5
61
62for.cond5:
63  %k.0 = phi i16 [ %inc, %for.inc ], [ 0, %for.cond5.preheader ]
64  br i1 %b0, label %for.inc14, label %for.inc
65
66for.inc:
67  %idxprom12 = zext i16 %k.0 to i32
68  %arrayidx13 = getelementptr inbounds [2 x [4 x [18 x i32]]], ptr @data, i32 0, i32 %idxprom, i32 %idxprom10, i32 %idxprom12
69  store i32 7, ptr %arrayidx13, align 1
70  %inc = add nuw nsw i16 %k.0, 1
71  br label %for.cond5
72
73for.inc14:
74  %inc15 = add nuw nsw i16 %j.0, 1
75  br label %for.cond1
76
77for.inc17:
78  %inc18 = add nuw nsw i16 %i.0, 1
79  br label %for.cond
80
81for.end19:
82  ret void
83}
84
85; Check IndexedReference::computeRefCost can handle negative stride
86
87; CHECK: Loop 'for.neg.cond' has cost = 64
88
89define void @handle_to_ptr_neg_stride(ptr %blocks) {
90; Preheader:
91entry:
92  br label %for.neg.cond
93
94; Loop:
95for.neg.cond:                                         ; preds = %for.neg.body, %entry
96  %i.0 = phi i32 [ 1023, %entry ], [ %dec, %for.neg.body ]
97  %cmp = icmp sgt i32 %i.0, 0
98  br i1 %cmp, label %for.neg.body, label %for.neg.end
99
100for.neg.body:                                         ; preds = %for.neg.cond
101  %idxprom = zext i32 %i.0 to i64
102  %arrayidx = getelementptr inbounds ptr, ptr %blocks, i64 %idxprom
103  store ptr null, ptr %arrayidx, align 8
104  %dec = add nsw i32 %i.0, -1
105  br label %for.neg.cond
106
107; Exit blocks
108for.neg.end:                                          ; preds = %for.neg.cond
109  ret void
110}
111
112
113
114;   for (int i = 40960; i > 0; i--)
115;     B[i] = B[40960 - i];
116
117; FIXME: Currently negative access functions are treated the same as positive
118; access functions. When this is fixed this testcase should have a cost
119; approximately 2x higher.
120
121; CHECK: Loop 'for.cond2' has cost = 2561
122define void @Test2(ptr %B) {
123entry:
124  br label %for.cond2
125
126for.cond2:                                         ; preds = %for.body, %entry
127  %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]
128  %cmp = icmp sgt i32 %i.0, 0
129  br i1 %cmp, label %for.body, label %for.end
130
131for.body:                                         ; preds = %for.cond
132  %sub = sub nsw i32 40960, %i.0
133  %idxprom = sext i32 %sub to i64
134  %arrayidx = getelementptr inbounds double, ptr %B, i64 %idxprom
135  %0 = load double, ptr %arrayidx, align 8
136  %idxprom1 = sext i32 %i.0 to i64
137  %arrayidx2 = getelementptr inbounds double, ptr %B, i64 %idxprom1
138  store double %0, ptr %arrayidx2, align 8
139  %dec = add nsw i32 %i.0, -1
140  br label %for.cond2
141
142for.end:                                          ; preds = %for.cond
143  ret void
144}
145
146
147
148;   for (i = 40960; i > 0; i--)
149;     C[i] = C[i];
150
151; CHECK: Loop 'for.cond3' has cost = 2561
152define void @Test3(ptr %C) {
153entry:
154  br label %for.cond3
155
156for.cond3:                                         ; preds = %for.body, %entry
157  %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]
158  %cmp = icmp sgt i32 %i.0, 0
159  br i1 %cmp, label %for.body, label %for.end
160
161for.body:                                         ; preds = %for.cond
162  %idxprom = sext i32 %i.0 to i64
163  %arrayidx = getelementptr inbounds ptr, ptr %C, i64 %idxprom
164  %0 = load ptr, ptr %arrayidx, align 8
165  %idxprom1 = sext i32 %i.0 to i64
166  %arrayidx2 = getelementptr inbounds ptr, ptr %C, i64 %idxprom1
167  store ptr %0, ptr %arrayidx2, align 8
168  %dec = add nsw i32 %i.0, -1
169  br label %for.cond3
170
171for.end:                                          ; preds = %for.cond
172  ret void
173}
174
175
176
177;  for (i = 0; i < 40960; i++)
178;     D[i] = D[i];
179
180; CHECK: Loop 'for.cond4' has cost = 2561
181define void @Test4(ptr %D) {
182entry:
183  br label %for.cond4
184
185for.cond4:                                         ; preds = %for.body, %entry
186  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
187  %cmp = icmp slt i32 %i.0, 40960
188  br i1 %cmp, label %for.body, label %for.end
189
190for.body:                                         ; preds = %for.cond
191  %idxprom = sext i32 %i.0 to i64
192  %arrayidx = getelementptr inbounds ptr, ptr %D, i64 %idxprom
193  %0 = load ptr, ptr %arrayidx, align 8
194  %idxprom1 = sext i32 %i.0 to i64
195  %arrayidx2 = getelementptr inbounds ptr, ptr %D, i64 %idxprom1
196  store ptr %0, ptr %arrayidx2, align 8
197  %inc = add nsw i32 %i.0, 1
198  br label %for.cond4
199
200for.end:                                          ; preds = %for.cond
201  ret void
202}
203