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 ; void foo(long n, long m, long o, int A[n][m][o]) {
7 ; for (long i = 0; i < n; i++)
8 ; for (long j = 0; j < m; j++)
9 ; for (long k = 0; k < o; k++)
10 ; A[2*i+3][3*j-4][2*k+7] = 1;
13 ; CHECK: Loop 'for.i' has cost = 100000000
14 ; CHECK-NEXT: Loop 'for.j' has cost = 1000000
15 ; CHECK-NEXT: Loop 'for.k' has cost = 70000
17 define void @foo(i64 %n, i64 %m, i64 %o, ptr %A) {
19 %cmp32 = icmp sgt i64 %n, 0
20 %cmp230 = icmp sgt i64 %m, 0
21 %cmp528 = icmp sgt i64 %o, 0
22 br i1 %cmp32, label %for.cond1.preheader.lr.ph, label %for.end
24 for.cond1.preheader.lr.ph: ; preds = %entry
25 br i1 %cmp230, label %for.i.preheader, label %for.end
27 for.i.preheader: ; preds = %for.cond1.preheader.lr.ph
28 br i1 %cmp528, label %for.i.preheader.split, label %for.end
30 for.i.preheader.split: ; preds = %for.i.preheader
33 for.i: ; preds = %for.inci, %for.i.preheader.split
34 %i = phi i64 [ %inci, %for.inci ], [ 0, %for.i.preheader.split ]
36 %add9 = add nsw i64 %mul8, 3
37 %0 = mul i64 %add9, %m
41 for.j: ; preds = %for.incj, %for.i
42 %j = phi i64 [ %incj, %for.incj ], [ 0, %for.i ]
43 %mul7 = mul nsw i64 %j, 3
44 %tmp = add i64 %sub, %mul7
45 %tmp27 = mul i64 %tmp, %o
48 for.k: ; preds = %for.k, %for.j.us
49 %k = phi i64 [ 0, %for.j ], [ %inck, %for.k ]
51 %mul = mul nsw i64 %k, 2
52 %arrayidx.sum = add i64 %mul, 7
53 %arrayidx10.sum = add i64 %arrayidx.sum, %tmp27
54 %arrayidx11 = getelementptr inbounds i32, ptr %A, i64 %arrayidx10.sum
55 store i32 1, ptr %arrayidx11, align 4
57 %inck = add nsw i64 %k, 1
58 %exitcond.us = icmp eq i64 %inck, %o
59 br i1 %exitcond.us, label %for.incj, label %for.k
61 for.incj: ; preds = %for.k
62 %incj = add nsw i64 %j, 1
63 %exitcond54.us = icmp eq i64 %incj, %m
64 br i1 %exitcond54.us, label %for.inci, label %for.j
66 for.inci: ; preds = %for.incj
67 %inci = add nsw i64 %i, 1
68 %exitcond55.us = icmp eq i64 %inci, %n
69 br i1 %exitcond55.us, label %for.end.loopexit, label %for.i
71 for.end.loopexit: ; preds = %for.inci
74 for.end: ; preds = %for.end.loopexit, %for.cond1.preheader.lr.ph, %entry
78 ; Loop i is supposed to have the largest cost and be placed
79 ; as the outermost loop. This test differs from foo() since the
80 ; loopnest has a suboptimal order j-i-k.
81 ; After D123400 we ensure that the order of loop cache analysis output
82 ; is loop i-j-k, despite the suboptimal order in the original loopnest.
84 ; void foo(long n, long m, long o, int A[n][m][o]) {
85 ; for (long j = 0; j < m; j++)
86 ; for (long i = 0; i < n; i++)
87 ; for (long k = 0; k < o; k++)
88 ; A[2*i+3][2*j-4][2*k+7] = 1;
91 ; CHECK: Loop 'for.i' has cost = 100000000
92 ; CHECK-NEXT: Loop 'for.j' has cost = 1000000
93 ; CHECK-NEXT: Loop 'for.k' has cost = 70000
95 define void @foo2(i64 %n, i64 %m, i64 %o, ptr %A) {
97 %cmp32 = icmp sgt i64 %n, 0
98 %cmp230 = icmp sgt i64 %m, 0
99 %cmp528 = icmp sgt i64 %o, 0
100 br i1 %cmp32, label %for.cond1.preheader.lr.ph, label %for.end
102 for.cond1.preheader.lr.ph: ; preds = %entry
103 br i1 %cmp230, label %for.j.preheader, label %for.end
105 for.j.preheader: ; preds = %for.cond1.preheader.lr.ph
106 br i1 %cmp528, label %for.j.preheader.split, label %for.end
108 for.j.preheader.split: ; preds = %for.j.preheader
111 for.i: ; preds = %for.inci, %for.j
112 %i = phi i64 [ %inci, %for.inci ], [ 0, %for.j ]
113 %mul8 = shl i64 %i, 1
114 %add9 = add nsw i64 %mul8, 3
115 %0 = mul i64 %add9, %m
116 %sub = add i64 %0, -4
117 %mul7 = mul nsw i64 %j, 2
118 %tmp = add i64 %sub, %mul7
119 %tmp27 = mul i64 %tmp, %o
122 for.j: ; preds = %for.incj, %for.j.preheader.split
123 %j = phi i64 [ %incj, %for.incj ], [ 0, %for.j.preheader.split ]
126 for.k: ; preds = %for.k, %for.i
127 %k = phi i64 [ 0, %for.i ], [ %inck, %for.k ]
129 %mul = mul nsw i64 %k, 2
130 %arrayidx.sum = add i64 %mul, 7
131 %arrayidx10.sum = add i64 %arrayidx.sum, %tmp27
132 %arrayidx11 = getelementptr inbounds i32, ptr %A, i64 %arrayidx10.sum
133 store i32 1, ptr %arrayidx11, align 4
135 %inck = add nsw i64 %k, 1
136 %exitcond.us = icmp eq i64 %inck, %o
137 br i1 %exitcond.us, label %for.inci, label %for.k
139 for.incj: ; preds = %for.inci
140 %incj = add nsw i64 %j, 1
141 %exitcond54.us = icmp eq i64 %incj, %m
142 br i1 %exitcond54.us, label %for.end.loopexit, label %for.j
144 for.inci: ; preds = %for.k
145 %inci = add nsw i64 %i, 1
146 %exitcond55.us = icmp eq i64 %inci, %n
147 br i1 %exitcond55.us, label %for.incj, label %for.i
149 for.end.loopexit: ; preds = %for.incj
152 for.end: ; preds = %for.end.loopexit, %for.cond1.preheader.lr.ph, %entry