1 ; RUN: opt < %s -passes='print<loop-cache-cost>' -disable-output 2>&1 | FileCheck %s
3 target datalayout = "e-m:e-i64:64-n32:64"
4 target triple = "powerpc64le-unknown-linux-gnu"
6 ; Check IndexedReference::computeRefCost can handle type differences between
9 ; CHECK: Loop 'for.cond' has cost = 64
11 %struct._Handleitem = type { %struct._Handleitem* }
13 define void @handle_to_ptr(%struct._Handleitem** %blocks) {
19 for.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
24 for.body: ; preds = %for.cond
25 %idxprom = zext i32 %i.0 to i64
26 %arrayidx = getelementptr inbounds %struct._Handleitem*, %struct._Handleitem** %blocks, i64 %idxprom
27 store %struct._Handleitem* null, %struct._Handleitem** %arrayidx, align 8
28 %inc = add nuw nsw i32 %i.0, 1
32 for.end: ; preds = %for.cond
38 ; Check IndexedReference::computeRefCost can handle negative stride
40 ; CHECK: Loop 'for.neg.cond' has cost = 64
42 define void @handle_to_ptr_neg_stride(%struct._Handleitem** %blocks) {
45 br label %for.neg.cond
48 for.neg.cond: ; preds = %for.neg.body, %entry
49 %i.0 = phi i32 [ 1023, %entry ], [ %dec, %for.neg.body ]
50 %cmp = icmp sgt i32 %i.0, 0
51 br i1 %cmp, label %for.neg.body, label %for.neg.end
53 for.neg.body: ; preds = %for.neg.cond
54 %idxprom = zext i32 %i.0 to i64
55 %arrayidx = getelementptr inbounds %struct._Handleitem*, %struct._Handleitem** %blocks, i64 %idxprom
56 store %struct._Handleitem* null, %struct._Handleitem** %arrayidx, align 8
57 %dec = add nsw i32 %i.0, -1
58 br label %for.neg.cond
61 for.neg.end: ; preds = %for.neg.cond
67 ; for (int i = 40960; i > 0; i--)
68 ; B[i] = B[40960 - i];
70 ; FIXME: Currently negative access functions are treated the same as positive
71 ; access functions. When this is fixed this testcase should have a cost
72 ; approximately 2x higher.
74 ; CHECK: Loop 'for.cond2' has cost = 2560
75 define void @Test2(double* %B) {
79 for.cond2: ; preds = %for.body, %entry
80 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]
81 %cmp = icmp sgt i32 %i.0, 0
82 br i1 %cmp, label %for.body, label %for.end
84 for.body: ; preds = %for.cond
85 %sub = sub nsw i32 40960, %i.0
86 %idxprom = sext i32 %sub to i64
87 %arrayidx = getelementptr inbounds double, double* %B, i64 %idxprom
88 %0 = load double, double* %arrayidx, align 8
89 %idxprom1 = sext i32 %i.0 to i64
90 %arrayidx2 = getelementptr inbounds double, double* %B, i64 %idxprom1
91 store double %0, double* %arrayidx2, align 8
92 %dec = add nsw i32 %i.0, -1
95 for.end: ; preds = %for.cond
101 ; for (i = 40960; i > 0; i--)
104 ; CHECK: Loop 'for.cond3' has cost = 2560
105 define void @Test3(double** %C) {
109 for.cond3: ; preds = %for.body, %entry
110 %i.0 = phi i32 [ 40960, %entry ], [ %dec, %for.body ]
111 %cmp = icmp sgt i32 %i.0, 0
112 br i1 %cmp, label %for.body, label %for.end
114 for.body: ; preds = %for.cond
115 %idxprom = sext i32 %i.0 to i64
116 %arrayidx = getelementptr inbounds double*, double** %C, i64 %idxprom
117 %0 = load double*, double** %arrayidx, align 8
118 %idxprom1 = sext i32 %i.0 to i64
119 %arrayidx2 = getelementptr inbounds double*, double** %C, i64 %idxprom1
120 store double* %0, double** %arrayidx2, align 8
121 %dec = add nsw i32 %i.0, -1
124 for.end: ; preds = %for.cond
130 ; for (i = 0; i < 40960; i++)
133 ; CHECK: Loop 'for.cond4' has cost = 2560
134 define void @Test4(double** %D) {
138 for.cond4: ; preds = %for.body, %entry
139 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
140 %cmp = icmp slt i32 %i.0, 40960
141 br i1 %cmp, label %for.body, label %for.end
143 for.body: ; preds = %for.cond
144 %idxprom = sext i32 %i.0 to i64
145 %arrayidx = getelementptr inbounds double*, double** %D, i64 %idxprom
146 %0 = load double*, double** %arrayidx, align 8
147 %idxprom1 = sext i32 %i.0 to i64
148 %arrayidx2 = getelementptr inbounds double*, double** %D, i64 %idxprom1
149 store double* %0, double** %arrayidx2, align 8
150 %inc = add nsw i32 %i.0, 1
153 for.end: ; preds = %for.cond