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,print<access-info>' -enable-loop-distribute \
5 ; RUN: -verify-loop-info -verify-dom-info -disable-output < %s 2>&1 | FileCheck %s --check-prefix=ANALYSIS
7 ; RUN: opt -aa-pipeline=basic-aa -passes=loop-distribute,loop-vectorize -enable-loop-distribute -force-vector-width=4 -S \
8 ; RUN: < %s | FileCheck %s --check-prefix=VECTORIZE
10 ; We should distribute this loop into a safe (2nd statement) and unsafe loop
12 ; for (i = 0; i < n; i++) {
13 ; A[i + 1] = A[i] * B[i];
14 ; =======================
18 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
19 target triple = "x86_64-apple-macosx10.10.0"
22 define void @f(ptr noalias %a,
30 ; Verify the two distributed loops.
32 ; CHECK: entry.split.ldist1:
33 ; CHECK: br label %for.body.ldist1
34 ; CHECK: for.body.ldist1:
35 ; CHECK: %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist1
36 ; CHECK: br i1 %exitcond.ldist1, label %entry.split, label %for.body.ldist1
39 ; CHECK: br label %for.body
41 ; CHECK: %mulC = mul i32 %loadD, %loadE
45 ; ANALYSIS: for.body.ldist1:
46 ; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop
48 ; ANALYSIS-NEXT: Memory dependences are safe{{$}}
51 ; VECTORIZE: mul <4 x i32>
53 for.body: ; preds = %for.body, %entry
54 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
56 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
57 %loadA = load i32, ptr %arrayidxA, align 4
59 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
60 %loadB = load i32, ptr %arrayidxB, align 4
62 %mulA = mul i32 %loadB, %loadA
64 %add = add nuw nsw i64 %ind, 1
65 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
66 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
68 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
69 %loadD = load i32, ptr %arrayidxD, align 4
71 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
72 %loadE = load i32, ptr %arrayidxE, align 4
74 %mulC = mul i32 %loadD, %loadE
76 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
77 store i32 %mulC, ptr %arrayidxC, align 4
79 %exitcond = icmp eq i64 %add, 20
80 br i1 %exitcond, label %for.end, label %for.body
82 for.end: ; preds = %for.body
86 declare i32 @llvm.convergent(i32) #0
88 ; It is OK to distribute with a convergent operation, since in each
89 ; new loop the convergent operation has the ssame control dependency.
90 ; CHECK-LABEL: @f_with_convergent(
91 define void @f_with_convergent(ptr noalias %a,
99 ; Verify the two distributed loops.
101 ; CHECK: entry.split.ldist1:
102 ; CHECK: br label %for.body.ldist1
103 ; CHECK: for.body.ldist1:
104 ; CHECK: %mulA.ldist1 = mul i32 %loadB.ldist1, %loadA.ldist1
105 ; CHECK: br i1 %exitcond.ldist1, label %entry.split, label %for.body.ldist1
107 ; CHECK: entry.split:
108 ; CHECK: br label %for.body
110 ; CHECK: %convergentD = call i32 @llvm.convergent(i32 %loadD)
111 ; CHECK: %mulC = mul i32 %convergentD, %loadE
115 ; ANALYSIS: for.body.ldist1:
116 ; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop
117 ; ANALYSIS: for.body:
118 ; ANALYSIS-NEXT: Has convergent operation in loop
119 ; ANALYSIS-NEXT: Report: cannot add control dependency to convergent operation
121 ; convergent instruction happens to block vectorization
122 ; VECTORIZE: call i32 @llvm.convergent
125 for.body: ; preds = %for.body, %entry
126 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
128 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %ind
129 %loadA = load i32, ptr %arrayidxA, align 4
131 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %ind
132 %loadB = load i32, ptr %arrayidxB, align 4
134 %mulA = mul i32 %loadB, %loadA
136 %add = add nuw nsw i64 %ind, 1
137 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
138 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
140 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %ind
141 %loadD = load i32, ptr %arrayidxD, align 4
143 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %ind
144 %loadE = load i32, ptr %arrayidxE, align 4
146 %convergentD = call i32 @llvm.convergent(i32 %loadD)
147 %mulC = mul i32 %convergentD, %loadE
149 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %ind
150 store i32 %mulC, ptr %arrayidxC, align 4
152 %exitcond = icmp eq i64 %add, 20
153 br i1 %exitcond, label %for.end, label %for.body
155 for.end: ; preds = %for.body
159 attributes #0 = { nounwind readnone convergent }