1 ; RUN: opt -basicaa -loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S \
2 ; RUN: < %s | FileCheck %s
4 ; RUN: opt -basicaa -loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info \
5 ; RUN: -loop-accesses -analyze < %s | FileCheck %s --check-prefix=ANALYSIS
7 ; RUN: opt -basicaa -loop-distribute -enable-loop-distribute -loop-vectorize -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(i32* 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
46 ; ANALYSIS-NEXT: Memory dependences are safe{{$}}
47 ; ANALYSIS: for.body.ldist1:
48 ; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop
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, i32* %a, i64 %ind
57 %loadA = load i32, i32* %arrayidxA, align 4
59 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
60 %loadB = load i32, i32* %arrayidxB, align 4
62 %mulA = mul i32 %loadB, %loadA
64 %add = add nuw nsw i64 %ind, 1
65 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
66 store i32 %mulA, i32* %arrayidxA_plus_4, align 4
68 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
69 %loadD = load i32, i32* %arrayidxD, align 4
71 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
72 %loadE = load i32, i32* %arrayidxE, align 4
74 %mulC = mul i32 %loadD, %loadE
76 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
77 store i32 %mulC, i32* %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(i32* 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:
116 ; ANALYSIS-NEXT: Has convergent operation in loop
117 ; ANALYSIS-NEXT: Report: cannot add control dependency to convergent operation
118 ; ANALYSIS: for.body.ldist1:
119 ; ANALYSIS-NEXT: Report: unsafe dependent memory operations in loop
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, i32* %a, i64 %ind
129 %loadA = load i32, i32* %arrayidxA, align 4
131 %arrayidxB = getelementptr inbounds i32, i32* %b, i64 %ind
132 %loadB = load i32, i32* %arrayidxB, align 4
134 %mulA = mul i32 %loadB, %loadA
136 %add = add nuw nsw i64 %ind, 1
137 %arrayidxA_plus_4 = getelementptr inbounds i32, i32* %a, i64 %add
138 store i32 %mulA, i32* %arrayidxA_plus_4, align 4
140 %arrayidxD = getelementptr inbounds i32, i32* %d, i64 %ind
141 %loadD = load i32, i32* %arrayidxD, align 4
143 %arrayidxE = getelementptr inbounds i32, i32* %e, i64 %ind
144 %loadE = load i32, i32* %arrayidxE, align 4
146 %convergentD = call i32 @llvm.convergent(i32 %loadD)
147 %mulC = mul i32 %convergentD, %loadE
149 %arrayidxC = getelementptr inbounds i32, i32* %c, i64 %ind
150 store i32 %mulC, i32* %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 }