1 ; RUN: opt -aa-pipeline=basic-aa -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S \
2 ; RUN: < %s | FileCheck %s
4 ; RUN: opt -aa-pipeline=basic-aa -passes='loop-distribute,loop-vectorize' -enable-loop-distribute -force-vector-width=4 \
5 ; RUN: -verify-loop-info -verify-dom-info -S < %s | \
6 ; RUN: FileCheck --check-prefix=VECTORIZE %s
8 ; RUN: opt -aa-pipeline=basic-aa -passes='loop-distribute,print<access-info>' -enable-loop-distribute \
9 ; RUN: -verify-loop-info -verify-dom-info -disable-output < %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
11 ; The memcheck version of basic.ll. We should distribute and vectorize the
12 ; second part of this loop with 5 memchecks (A+1 x {C, D, E} + C x {A, B})
14 ; for (i = 0; i < n; i++) {
15 ; A[i + 1] = A[i] * B[i];
16 ; -------------------------------
20 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
21 target triple = "x86_64-apple-macosx10.10.0"
23 @B = common global ptr null, align 8
24 @A = common global ptr null, align 8
25 @C = common global ptr null, align 8
26 @D = common global ptr null, align 8
27 @E = common global ptr null, align 8
32 %a = load ptr, ptr @A, align 8
33 %b = load ptr, ptr @B, align 8
34 %c = load ptr, ptr @C, align 8
35 %d = load ptr, ptr @D, align 8
36 %e = load ptr, ptr @E, align 8
39 ; We have two compares for each array overlap check.
40 ; Since the checks to A and A + 4 get merged, this will give us a
41 ; total of 8 compares.
43 ; CHECK: for.body.lver.check:
57 ; CHECK: br i1 %conflict.rdx15, label %for.body.ph.lver.orig, label %for.body.ph.ldist1
59 ; The non-distributed loop that the memchecks fall back on.
61 ; CHECK: for.body.ph.lver.orig:
62 ; CHECK: br label %for.body.lver.orig
63 ; CHECK: for.body.lver.orig:
64 ; CHECK: br i1 %exitcond.lver.orig, label %for.end.loopexit, label %for.body.lver.orig
66 ; Verify the two distributed loops.
68 ; CHECK: for.body.ph.ldist1:
69 ; CHECK: br label %for.body.ldist1
70 ; CHECK: for.body.ldist1:
71 ; CHECK: %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist1
72 ; CHECK: br i1 %exitcond.ldist1, label %for.body.ph, label %for.body.ldist1
75 ; CHECK: br label %for.body
77 ; CHECK: %mulC = mul i32 %loadD, %loadE
81 ; VECTORIZE: mul <4 x i32>
83 for.body: ; preds = %for.body, %entry
84 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
86 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
87 %loadA = load i32, ptr %arrayidxA, align 4
89 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
90 %loadB = load i32, ptr %arrayidxB, align 4
92 %mulA = mul i32 %loadB, %loadA
94 %add = add nuw nsw i64 %ind, 1
95 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
96 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
98 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
99 %loadD = load i32, ptr %arrayidxD, align 4
101 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
102 %loadE = load i32, ptr %arrayidxE, align 4
104 %mulC = mul i32 %loadD, %loadE
106 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
107 store i32 %mulC, ptr %arrayidxC, align 4
109 %exitcond = icmp eq i64 %add, 20
110 br i1 %exitcond, label %for.end, label %for.body
112 for.end: ; preds = %for.body
116 ; Make sure there's no "Multiple reports generated" assert with a
117 ; volatile load, and no distribution
119 ; TODO: Distribution of volatile may be possible under some
120 ; circumstance, but the current implementation does not touch them.
122 ; CHECK-LABEL: @f_volatile_load(
123 ; CHECK: br label %for.body{{$}}
127 ; CHECK: {{^}}for.body:
130 ; CHECK: load volatile i32
132 ; CHECK: br i1 %exitcond, label %for.end, label %for.body{{$}}
136 ; VECTORIZE-NOT: load <4 x i32>
137 ; VECTORIZE-NOT: mul <4 x i32>
138 define void @f_volatile_load() {
140 %a = load ptr, ptr @A, align 8
141 %b = load ptr, ptr @B, align 8
142 %c = load ptr, ptr @C, align 8
143 %d = load ptr, ptr @D, align 8
144 %e = load ptr, ptr @E, align 8
148 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
150 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
151 %loadA = load i32, ptr %arrayidxA, align 4
153 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
154 %loadB = load i32, ptr %arrayidxB, align 4
156 %mulA = mul i32 %loadB, %loadA
158 %add = add nuw nsw i64 %ind, 1
159 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
160 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
162 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
163 %loadD = load volatile i32, ptr %arrayidxD, align 4
165 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
166 %loadE = load i32, ptr %arrayidxE, align 4
168 %mulC = mul i32 %loadD, %loadE
170 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
171 store i32 %mulC, ptr %arrayidxC, align 4
173 %exitcond = icmp eq i64 %add, 20
174 br i1 %exitcond, label %for.end, label %for.body
180 declare i32 @llvm.convergent(i32) #0
182 ; This is the same as f, and would require the same bounds
183 ; check. However, it is not OK to introduce new control dependencies
184 ; on the convergent call.
186 ; CHECK-LABEL: @f_with_convergent(
187 ; CHECK: call i32 @llvm.convergent
188 ; CHECK-NOT: call i32 @llvm.convergent
190 ; ANALYSIS: for.body:
191 ; ANALYSIS: Report: cannot add control dependency to convergent operation
192 define void @f_with_convergent() #1 {
194 %a = load ptr, ptr @A, align 8
195 %b = load ptr, ptr @B, align 8
196 %c = load ptr, ptr @C, align 8
197 %d = load ptr, ptr @D, align 8
198 %e = load ptr, ptr @E, align 8
201 for.body: ; preds = %for.body, %entry
202 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
204 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
205 %loadA = load i32, ptr %arrayidxA, align 4
207 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
208 %loadB = load i32, ptr %arrayidxB, align 4
210 %mulA = mul i32 %loadB, %loadA
212 %add = add nuw nsw i64 %ind, 1
213 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
214 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
216 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
217 %loadD = load i32, ptr %arrayidxD, align 4
219 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
220 %loadE = load i32, ptr %arrayidxE, align 4
222 %convergentD = call i32 @llvm.convergent(i32 %loadD)
223 %mulC = mul i32 %convergentD, %loadE
225 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
226 store i32 %mulC, ptr %arrayidxC, align 4
228 %exitcond = icmp eq i64 %add, 20
229 br i1 %exitcond, label %for.end, label %for.body
231 for.end: ; preds = %for.body
235 ; Make sure an explicit request for distribution is ignored if it
236 ; requires possibly illegal checks.
238 ; CHECK-LABEL: @f_with_convergent_forced_distribute(
239 ; CHECK: call i32 @llvm.convergent
240 ; CHECK-NOT: call i32 @llvm.convergent
241 define void @f_with_convergent_forced_distribute() #1 {
243 %a = load ptr, ptr @A, align 8
244 %b = load ptr, ptr @B, align 8
245 %c = load ptr, ptr @C, align 8
246 %d = load ptr, ptr @D, align 8
247 %e = load ptr, ptr @E, align 8
250 for.body: ; preds = %for.body, %entry
251 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
253 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
254 %loadA = load i32, ptr %arrayidxA, align 4
256 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
257 %loadB = load i32, ptr %arrayidxB, align 4
259 %mulA = mul i32 %loadB, %loadA
261 %add = add nuw nsw i64 %ind, 1
262 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
263 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
265 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
266 %loadD = load i32, ptr %arrayidxD, align 4
268 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
269 %loadE = load i32, ptr %arrayidxE, align 4
271 %convergentD = call i32 @llvm.convergent(i32 %loadD)
272 %mulC = mul i32 %convergentD, %loadE
274 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
275 store i32 %mulC, ptr %arrayidxC, align 4
277 %exitcond = icmp eq i64 %add, 20
278 br i1 %exitcond, label %for.end, label %for.body, !llvm.loop !0
280 for.end: ; preds = %for.body
284 attributes #0 = { nounwind readnone convergent }
285 attributes #1 = { nounwind convergent }
287 !0 = distinct !{!0, !1}
288 !1 = !{!"llvm.loop.distribute.enable", i1 true}