1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-distribute -enable-loop-distribute -verify-loop-info -verify-dom-info -S -enable-mem-access-versioning=0 < %s | FileCheck %s
4 ; PredicatedScalarEvolution decides it needs to insert a bounds check
5 ; not based on memory access.
7 define void @f(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e, i64 %N) {
10 ; CHECK-NEXT: br label [[FOR_BODY_LVER_CHECK:%.*]]
11 ; CHECK: for.body.lver.check:
12 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[N:%.*]], -1
13 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i64 [[TMP0]], 4294967295
14 ; CHECK-NEXT: [[MUL1:%.*]] = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 8, i64 [[TMP0]])
15 ; CHECK-NEXT: [[MUL_RESULT:%.*]] = extractvalue { i64, i1 } [[MUL1]], 0
16 ; CHECK-NEXT: [[MUL_OVERFLOW:%.*]] = extractvalue { i64, i1 } [[MUL1]], 1
17 ; CHECK-NEXT: [[TMP2:%.*]] = sub i64 0, [[MUL_RESULT]]
18 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 [[MUL_RESULT]]
19 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult ptr [[TMP3]], [[A]]
20 ; CHECK-NEXT: [[TMP5:%.*]] = or i1 [[TMP4]], [[MUL_OVERFLOW]]
21 ; CHECK-NEXT: [[TMP6:%.*]] = or i1 [[TMP1]], [[TMP5]]
22 ; CHECK-NEXT: br i1 [[TMP6]], label [[FOR_BODY_PH_LVER_ORIG:%.*]], label [[FOR_BODY_PH_LDIST1:%.*]]
23 ; CHECK: for.body.ph.lver.orig:
24 ; CHECK-NEXT: br label [[FOR_BODY_LVER_ORIG:%.*]]
25 ; CHECK: for.body.lver.orig:
26 ; CHECK-NEXT: [[IND_LVER_ORIG:%.*]] = phi i64 [ 0, [[FOR_BODY_PH_LVER_ORIG]] ], [ [[ADD_LVER_ORIG:%.*]], [[FOR_BODY_LVER_ORIG]] ]
27 ; CHECK-NEXT: [[IND1_LVER_ORIG:%.*]] = phi i32 [ 0, [[FOR_BODY_PH_LVER_ORIG]] ], [ [[INC1_LVER_ORIG:%.*]], [[FOR_BODY_LVER_ORIG]] ]
28 ; CHECK-NEXT: [[MUL_LVER_ORIG:%.*]] = mul i32 [[IND1_LVER_ORIG]], 2
29 ; CHECK-NEXT: [[MUL_EXT_LVER_ORIG:%.*]] = zext i32 [[MUL_LVER_ORIG]] to i64
30 ; CHECK-NEXT: [[ARRAYIDXA_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[MUL_EXT_LVER_ORIG]]
31 ; CHECK-NEXT: [[LOADA_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXA_LVER_ORIG]], align 4
32 ; CHECK-NEXT: [[ARRAYIDXB_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
33 ; CHECK-NEXT: [[LOADB_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXB_LVER_ORIG]], align 4
34 ; CHECK-NEXT: [[MULA_LVER_ORIG:%.*]] = mul i32 [[LOADB_LVER_ORIG]], [[LOADA_LVER_ORIG]]
35 ; CHECK-NEXT: [[ADD_LVER_ORIG]] = add nuw nsw i64 [[IND_LVER_ORIG]], 1
36 ; CHECK-NEXT: [[INC1_LVER_ORIG]] = add i32 [[IND1_LVER_ORIG]], 1
37 ; CHECK-NEXT: [[ARRAYIDXA_PLUS_4_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[ADD_LVER_ORIG]]
38 ; CHECK-NEXT: store i32 [[MULA_LVER_ORIG]], ptr [[ARRAYIDXA_PLUS_4_LVER_ORIG]], align 4
39 ; CHECK-NEXT: [[ARRAYIDXD_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[D:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
40 ; CHECK-NEXT: [[LOADD_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXD_LVER_ORIG]], align 4
41 ; CHECK-NEXT: [[ARRAYIDXE_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[E:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
42 ; CHECK-NEXT: [[LOADE_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXE_LVER_ORIG]], align 4
43 ; CHECK-NEXT: [[MULC_LVER_ORIG:%.*]] = mul i32 [[LOADD_LVER_ORIG]], [[LOADE_LVER_ORIG]]
44 ; CHECK-NEXT: [[ARRAYIDXC_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
45 ; CHECK-NEXT: store i32 [[MULC_LVER_ORIG]], ptr [[ARRAYIDXC_LVER_ORIG]], align 4
46 ; CHECK-NEXT: [[EXITCOND_LVER_ORIG:%.*]] = icmp eq i64 [[ADD_LVER_ORIG]], [[N]]
47 ; CHECK-NEXT: br i1 [[EXITCOND_LVER_ORIG]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY_LVER_ORIG]]
48 ; CHECK: for.body.ph.ldist1:
49 ; CHECK-NEXT: br label [[FOR_BODY_LDIST1:%.*]]
50 ; CHECK: for.body.ldist1:
51 ; CHECK-NEXT: [[IND_LDIST1:%.*]] = phi i64 [ 0, [[FOR_BODY_PH_LDIST1]] ], [ [[ADD_LDIST1:%.*]], [[FOR_BODY_LDIST1]] ]
52 ; CHECK-NEXT: [[IND1_LDIST1:%.*]] = phi i32 [ 0, [[FOR_BODY_PH_LDIST1]] ], [ [[INC1_LDIST1:%.*]], [[FOR_BODY_LDIST1]] ]
53 ; CHECK-NEXT: [[MUL_LDIST1:%.*]] = mul i32 [[IND1_LDIST1]], 2
54 ; CHECK-NEXT: [[MUL_EXT_LDIST1:%.*]] = zext i32 [[MUL_LDIST1]] to i64
55 ; CHECK-NEXT: [[ARRAYIDXA_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[MUL_EXT_LDIST1]]
56 ; CHECK-NEXT: [[LOADA_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXA_LDIST1]], align 4, !alias.scope !0
57 ; CHECK-NEXT: [[ARRAYIDXB_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[MUL_EXT_LDIST1]]
58 ; CHECK-NEXT: [[LOADB_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXB_LDIST1]], align 4
59 ; CHECK-NEXT: [[MULA_LDIST1:%.*]] = mul i32 [[LOADB_LDIST1]], [[LOADA_LDIST1]]
60 ; CHECK-NEXT: [[ADD_LDIST1]] = add nuw nsw i64 [[IND_LDIST1]], 1
61 ; CHECK-NEXT: [[INC1_LDIST1]] = add i32 [[IND1_LDIST1]], 1
62 ; CHECK-NEXT: [[ARRAYIDXA_PLUS_4_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[ADD_LDIST1]]
63 ; CHECK-NEXT: store i32 [[MULA_LDIST1]], ptr [[ARRAYIDXA_PLUS_4_LDIST1]], align 4, !alias.scope !3
64 ; CHECK-NEXT: [[EXITCOND_LDIST1:%.*]] = icmp eq i64 [[ADD_LDIST1]], [[N]]
65 ; CHECK-NEXT: br i1 [[EXITCOND_LDIST1]], label [[FOR_BODY_PH:%.*]], label [[FOR_BODY_LDIST1]]
67 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
69 ; CHECK-NEXT: [[IND:%.*]] = phi i64 [ 0, [[FOR_BODY_PH]] ], [ [[ADD:%.*]], [[FOR_BODY]] ]
70 ; CHECK-NEXT: [[IND1:%.*]] = phi i32 [ 0, [[FOR_BODY_PH]] ], [ [[INC1:%.*]], [[FOR_BODY]] ]
71 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[IND1]], 2
72 ; CHECK-NEXT: [[MUL_EXT:%.*]] = zext i32 [[MUL]] to i64
73 ; CHECK-NEXT: [[ADD]] = add nuw nsw i64 [[IND]], 1
74 ; CHECK-NEXT: [[INC1]] = add i32 [[IND1]], 1
75 ; CHECK-NEXT: [[ARRAYIDXD:%.*]] = getelementptr inbounds i32, ptr [[D]], i64 [[MUL_EXT]]
76 ; CHECK-NEXT: [[LOADD:%.*]] = load i32, ptr [[ARRAYIDXD]], align 4
77 ; CHECK-NEXT: [[ARRAYIDXE:%.*]] = getelementptr inbounds i32, ptr [[E]], i64 [[MUL_EXT]]
78 ; CHECK-NEXT: [[LOADE:%.*]] = load i32, ptr [[ARRAYIDXE]], align 4
79 ; CHECK-NEXT: [[MULC:%.*]] = mul i32 [[LOADD]], [[LOADE]]
80 ; CHECK-NEXT: [[ARRAYIDXC:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[MUL_EXT]]
81 ; CHECK-NEXT: store i32 [[MULC]], ptr [[ARRAYIDXC]], align 4
82 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[ADD]], [[N]]
83 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END_LOOPEXIT2:%.*]], label [[FOR_BODY]]
84 ; CHECK: for.end.loopexit:
85 ; CHECK-NEXT: br label [[FOR_END:%.*]]
86 ; CHECK: for.end.loopexit2:
87 ; CHECK-NEXT: br label [[FOR_END]]
89 ; CHECK-NEXT: ret void
94 for.body: ; preds = %for.body, %entry
95 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
96 %ind1 = phi i32 [ 0, %entry ], [ %inc1, %for.body ]
98 %mul = mul i32 %ind1, 2
99 %mul_ext = zext i32 %mul to i64
102 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %mul_ext
103 %loadA = load i32, ptr %arrayidxA, align 4
105 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %mul_ext
106 %loadB = load i32, ptr %arrayidxB, align 4
108 %mulA = mul i32 %loadB, %loadA
110 %add = add nuw nsw i64 %ind, 1
111 %inc1 = add i32 %ind1, 1
113 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
114 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
116 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %mul_ext
117 %loadD = load i32, ptr %arrayidxD, align 4
119 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %mul_ext
120 %loadE = load i32, ptr %arrayidxE, align 4
122 %mulC = mul i32 %loadD, %loadE
124 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %mul_ext
125 store i32 %mulC, ptr %arrayidxC, align 4
127 %exitcond = icmp eq i64 %add, %N
128 br i1 %exitcond, label %for.end, label %for.body
130 for.end: ; preds = %for.body
134 declare void @use64(i64)
135 @global_a = common local_unnamed_addr global [8192 x i32] zeroinitializer, align 16
137 define void @f_with_offset(ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e, i64 %N) {
138 ; CHECK-LABEL: @f_with_offset(
140 ; CHECK-NEXT: [[A_INTPTR:%.*]] = ptrtoint ptr @global_a to i64
141 ; CHECK-NEXT: call void @use64(i64 [[A_INTPTR]])
142 ; CHECK-NEXT: [[A:%.*]] = getelementptr i32, ptr @global_a, i32 42
143 ; CHECK-NEXT: br label [[FOR_BODY_LVER_CHECK:%.*]]
144 ; CHECK: for.body.lver.check:
145 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[N:%.*]], -1
146 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i64 [[TMP0]], 4294967295
147 ; CHECK-NEXT: [[MUL1:%.*]] = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 8, i64 [[TMP0]])
148 ; CHECK-NEXT: [[MUL_RESULT:%.*]] = extractvalue { i64, i1 } [[MUL1]], 0
149 ; CHECK-NEXT: [[MUL_OVERFLOW:%.*]] = extractvalue { i64, i1 } [[MUL1]], 1
150 ; CHECK-NEXT: [[TMP2:%.*]] = sub i64 0, [[MUL_RESULT]]
151 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i8, ptr [[A]], i64 [[MUL_RESULT]]
152 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult ptr [[TMP3]], [[A]]
153 ; CHECK-NEXT: [[TMP5:%.*]] = or i1 [[TMP4]], [[MUL_OVERFLOW]]
154 ; CHECK-NEXT: [[TMP6:%.*]] = or i1 [[TMP1]], [[TMP5]]
155 ; CHECK-NEXT: br i1 [[TMP6]], label [[FOR_BODY_PH_LVER_ORIG:%.*]], label [[FOR_BODY_PH_LDIST1:%.*]]
156 ; CHECK: for.body.ph.lver.orig:
157 ; CHECK-NEXT: br label [[FOR_BODY_LVER_ORIG:%.*]]
158 ; CHECK: for.body.lver.orig:
159 ; CHECK-NEXT: [[IND_LVER_ORIG:%.*]] = phi i64 [ 0, [[FOR_BODY_PH_LVER_ORIG]] ], [ [[ADD_LVER_ORIG:%.*]], [[FOR_BODY_LVER_ORIG]] ]
160 ; CHECK-NEXT: [[IND1_LVER_ORIG:%.*]] = phi i32 [ 0, [[FOR_BODY_PH_LVER_ORIG]] ], [ [[INC1_LVER_ORIG:%.*]], [[FOR_BODY_LVER_ORIG]] ]
161 ; CHECK-NEXT: [[MUL_LVER_ORIG:%.*]] = mul i32 [[IND1_LVER_ORIG]], 2
162 ; CHECK-NEXT: [[MUL_EXT_LVER_ORIG:%.*]] = zext i32 [[MUL_LVER_ORIG]] to i64
163 ; CHECK-NEXT: [[ARRAYIDXA_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[MUL_EXT_LVER_ORIG]]
164 ; CHECK-NEXT: [[LOADA_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXA_LVER_ORIG]], align 4
165 ; CHECK-NEXT: [[ARRAYIDXB_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
166 ; CHECK-NEXT: [[LOADB_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXB_LVER_ORIG]], align 4
167 ; CHECK-NEXT: [[MULA_LVER_ORIG:%.*]] = mul i32 [[LOADB_LVER_ORIG]], [[LOADA_LVER_ORIG]]
168 ; CHECK-NEXT: [[ADD_LVER_ORIG]] = add nuw nsw i64 [[IND_LVER_ORIG]], 1
169 ; CHECK-NEXT: [[INC1_LVER_ORIG]] = add i32 [[IND1_LVER_ORIG]], 1
170 ; CHECK-NEXT: [[ARRAYIDXA_PLUS_4_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[ADD_LVER_ORIG]]
171 ; CHECK-NEXT: store i32 [[MULA_LVER_ORIG]], ptr [[ARRAYIDXA_PLUS_4_LVER_ORIG]], align 4
172 ; CHECK-NEXT: [[ARRAYIDXD_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[D:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
173 ; CHECK-NEXT: [[LOADD_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXD_LVER_ORIG]], align 4
174 ; CHECK-NEXT: [[ARRAYIDXE_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[E:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
175 ; CHECK-NEXT: [[LOADE_LVER_ORIG:%.*]] = load i32, ptr [[ARRAYIDXE_LVER_ORIG]], align 4
176 ; CHECK-NEXT: [[MULC_LVER_ORIG:%.*]] = mul i32 [[LOADD_LVER_ORIG]], [[LOADE_LVER_ORIG]]
177 ; CHECK-NEXT: [[ARRAYIDXC_LVER_ORIG:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i64 [[MUL_EXT_LVER_ORIG]]
178 ; CHECK-NEXT: store i32 [[MULC_LVER_ORIG]], ptr [[ARRAYIDXC_LVER_ORIG]], align 4
179 ; CHECK-NEXT: [[EXITCOND_LVER_ORIG:%.*]] = icmp eq i64 [[ADD_LVER_ORIG]], [[N]]
180 ; CHECK-NEXT: br i1 [[EXITCOND_LVER_ORIG]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY_LVER_ORIG]]
181 ; CHECK: for.body.ph.ldist1:
182 ; CHECK-NEXT: br label [[FOR_BODY_LDIST1:%.*]]
183 ; CHECK: for.body.ldist1:
184 ; CHECK-NEXT: [[IND_LDIST1:%.*]] = phi i64 [ 0, [[FOR_BODY_PH_LDIST1]] ], [ [[ADD_LDIST1:%.*]], [[FOR_BODY_LDIST1]] ]
185 ; CHECK-NEXT: [[IND1_LDIST1:%.*]] = phi i32 [ 0, [[FOR_BODY_PH_LDIST1]] ], [ [[INC1_LDIST1:%.*]], [[FOR_BODY_LDIST1]] ]
186 ; CHECK-NEXT: [[MUL_LDIST1:%.*]] = mul i32 [[IND1_LDIST1]], 2
187 ; CHECK-NEXT: [[MUL_EXT_LDIST1:%.*]] = zext i32 [[MUL_LDIST1]] to i64
188 ; CHECK-NEXT: [[ARRAYIDXA_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[MUL_EXT_LDIST1]]
189 ; CHECK-NEXT: [[LOADA_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXA_LDIST1]], align 4, !alias.scope !5
190 ; CHECK-NEXT: [[ARRAYIDXB_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[MUL_EXT_LDIST1]]
191 ; CHECK-NEXT: [[LOADB_LDIST1:%.*]] = load i32, ptr [[ARRAYIDXB_LDIST1]], align 4
192 ; CHECK-NEXT: [[MULA_LDIST1:%.*]] = mul i32 [[LOADB_LDIST1]], [[LOADA_LDIST1]]
193 ; CHECK-NEXT: [[ADD_LDIST1]] = add nuw nsw i64 [[IND_LDIST1]], 1
194 ; CHECK-NEXT: [[INC1_LDIST1]] = add i32 [[IND1_LDIST1]], 1
195 ; CHECK-NEXT: [[ARRAYIDXA_PLUS_4_LDIST1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[ADD_LDIST1]]
196 ; CHECK-NEXT: store i32 [[MULA_LDIST1]], ptr [[ARRAYIDXA_PLUS_4_LDIST1]], align 4, !alias.scope !8
197 ; CHECK-NEXT: [[EXITCOND_LDIST1:%.*]] = icmp eq i64 [[ADD_LDIST1]], [[N]]
198 ; CHECK-NEXT: br i1 [[EXITCOND_LDIST1]], label [[FOR_BODY_PH:%.*]], label [[FOR_BODY_LDIST1]]
199 ; CHECK: for.body.ph:
200 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
202 ; CHECK-NEXT: [[IND:%.*]] = phi i64 [ 0, [[FOR_BODY_PH]] ], [ [[ADD:%.*]], [[FOR_BODY]] ]
203 ; CHECK-NEXT: [[IND1:%.*]] = phi i32 [ 0, [[FOR_BODY_PH]] ], [ [[INC1:%.*]], [[FOR_BODY]] ]
204 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[IND1]], 2
205 ; CHECK-NEXT: [[MUL_EXT:%.*]] = zext i32 [[MUL]] to i64
206 ; CHECK-NEXT: [[ADD]] = add nuw nsw i64 [[IND]], 1
207 ; CHECK-NEXT: [[INC1]] = add i32 [[IND1]], 1
208 ; CHECK-NEXT: [[ARRAYIDXD:%.*]] = getelementptr inbounds i32, ptr [[D]], i64 [[MUL_EXT]]
209 ; CHECK-NEXT: [[LOADD:%.*]] = load i32, ptr [[ARRAYIDXD]], align 4
210 ; CHECK-NEXT: [[ARRAYIDXE:%.*]] = getelementptr inbounds i32, ptr [[E]], i64 [[MUL_EXT]]
211 ; CHECK-NEXT: [[LOADE:%.*]] = load i32, ptr [[ARRAYIDXE]], align 4
212 ; CHECK-NEXT: [[MULC:%.*]] = mul i32 [[LOADD]], [[LOADE]]
213 ; CHECK-NEXT: [[ARRAYIDXC:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[MUL_EXT]]
214 ; CHECK-NEXT: store i32 [[MULC]], ptr [[ARRAYIDXC]], align 4
215 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[ADD]], [[N]]
216 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END_LOOPEXIT2:%.*]], label [[FOR_BODY]]
217 ; CHECK: for.end.loopexit:
218 ; CHECK-NEXT: br label [[FOR_END:%.*]]
219 ; CHECK: for.end.loopexit2:
220 ; CHECK-NEXT: br label [[FOR_END]]
222 ; CHECK-NEXT: ret void
225 %a_intptr = ptrtoint ptr @global_a to i64
226 call void @use64(i64 %a_intptr)
227 %a = getelementptr i32, ptr @global_a, i32 42
230 for.body: ; preds = %for.body, %entry
231 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
232 %ind1 = phi i32 [ 0, %entry ], [ %inc1, %for.body ]
234 %mul = mul i32 %ind1, 2
235 %mul_ext = zext i32 %mul to i64
238 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %mul_ext
239 %loadA = load i32, ptr %arrayidxA, align 4
241 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %mul_ext
242 %loadB = load i32, ptr %arrayidxB, align 4
244 %mulA = mul i32 %loadB, %loadA
246 %add = add nuw nsw i64 %ind, 1
247 %inc1 = add i32 %ind1, 1
249 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
250 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
252 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %mul_ext
253 %loadD = load i32, ptr %arrayidxD, align 4
255 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %mul_ext
256 %loadE = load i32, ptr %arrayidxE, align 4
258 %mulC = mul i32 %loadD, %loadE
260 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %mul_ext
261 store i32 %mulC, ptr %arrayidxC, align 4
263 %exitcond = icmp eq i64 %add, %N
264 br i1 %exitcond, label %for.end, label %for.body
266 for.end: ; preds = %for.body
270 ; Can't add control dependency with convergent in loop body.
271 define void @f_with_convergent(ptr noalias %a, ptr noalias %b, ptr noalias %c, ptr noalias %d, ptr noalias %e, i64 %N) #1 {
272 ; CHECK-LABEL: @f_with_convergent(
274 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
276 ; CHECK-NEXT: [[IND:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[ADD:%.*]], [[FOR_BODY]] ]
277 ; CHECK-NEXT: [[IND1:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[INC1:%.*]], [[FOR_BODY]] ]
278 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[IND1]], 2
279 ; CHECK-NEXT: [[MUL_EXT:%.*]] = zext i32 [[MUL]] to i64
280 ; CHECK-NEXT: [[ARRAYIDXA:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[MUL_EXT]]
281 ; CHECK-NEXT: [[LOADA:%.*]] = load i32, ptr [[ARRAYIDXA]], align 4
282 ; CHECK-NEXT: [[ARRAYIDXB:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i64 [[MUL_EXT]]
283 ; CHECK-NEXT: [[LOADB:%.*]] = load i32, ptr [[ARRAYIDXB]], align 4
284 ; CHECK-NEXT: [[MULA:%.*]] = mul i32 [[LOADB]], [[LOADA]]
285 ; CHECK-NEXT: [[ADD]] = add nuw nsw i64 [[IND]], 1
286 ; CHECK-NEXT: [[INC1]] = add i32 [[IND1]], 1
287 ; CHECK-NEXT: [[ARRAYIDXA_PLUS_4:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[ADD]]
288 ; CHECK-NEXT: store i32 [[MULA]], ptr [[ARRAYIDXA_PLUS_4]], align 4
289 ; CHECK-NEXT: [[ARRAYIDXD:%.*]] = getelementptr inbounds i32, ptr [[D:%.*]], i64 [[MUL_EXT]]
290 ; CHECK-NEXT: [[LOADD:%.*]] = load i32, ptr [[ARRAYIDXD]], align 4
291 ; CHECK-NEXT: [[ARRAYIDXE:%.*]] = getelementptr inbounds i32, ptr [[E:%.*]], i64 [[MUL_EXT]]
292 ; CHECK-NEXT: [[LOADE:%.*]] = load i32, ptr [[ARRAYIDXE]], align 4
293 ; CHECK-NEXT: [[CONVERGENTD:%.*]] = call i32 @llvm.convergent(i32 [[LOADD]])
294 ; CHECK-NEXT: [[MULC:%.*]] = mul i32 [[CONVERGENTD]], [[LOADE]]
295 ; CHECK-NEXT: [[ARRAYIDXC:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i64 [[MUL_EXT]]
296 ; CHECK-NEXT: store i32 [[MULC]], ptr [[ARRAYIDXC]], align 4
297 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[ADD]], [[N:%.*]]
298 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]
300 ; CHECK-NEXT: ret void
305 for.body: ; preds = %for.body, %entry
306 %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]
307 %ind1 = phi i32 [ 0, %entry ], [ %inc1, %for.body ]
309 %mul = mul i32 %ind1, 2
310 %mul_ext = zext i32 %mul to i64
313 %arrayidxA = getelementptr inbounds i32, ptr %a, i64 %mul_ext
314 %loadA = load i32, ptr %arrayidxA, align 4
316 %arrayidxB = getelementptr inbounds i32, ptr %b, i64 %mul_ext
317 %loadB = load i32, ptr %arrayidxB, align 4
319 %mulA = mul i32 %loadB, %loadA
321 %add = add nuw nsw i64 %ind, 1
322 %inc1 = add i32 %ind1, 1
324 %arrayidxA_plus_4 = getelementptr inbounds i32, ptr %a, i64 %add
325 store i32 %mulA, ptr %arrayidxA_plus_4, align 4
327 %arrayidxD = getelementptr inbounds i32, ptr %d, i64 %mul_ext
328 %loadD = load i32, ptr %arrayidxD, align 4
330 %arrayidxE = getelementptr inbounds i32, ptr %e, i64 %mul_ext
331 %loadE = load i32, ptr %arrayidxE, align 4
333 %convergentD = call i32 @llvm.convergent(i32 %loadD)
334 %mulC = mul i32 %convergentD, %loadE
336 %arrayidxC = getelementptr inbounds i32, ptr %c, i64 %mul_ext
337 store i32 %mulC, ptr %arrayidxC, align 4
339 %exitcond = icmp eq i64 %add, %N
340 br i1 %exitcond, label %for.end, label %for.body
342 for.end: ; preds = %for.body
346 declare i32 @llvm.convergent(i32) #0
348 attributes #0 = { nounwind readnone convergent }
349 attributes #1 = { nounwind convergent }