[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / test / Analysis / MemorySSA / phi-translation.ll
blob7a7206a8a9e1fdaed39523593a3aa904842aed71
1 ; RUN: opt -aa-pipeline=basic-aa -passes='print<memoryssa>,verify<memoryssa>' -disable-output < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,NOLIMIT
2 ; RUN: opt -memssa-check-limit=0 -aa-pipeline=basic-aa -passes='print<memoryssa>,verify<memoryssa>' -disable-output < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,LIMIT
4 ; %ptr can't alias %local, so we should be able to optimize the use of %local to
5 ; point to the store to %local.
6 ; CHECK-LABEL: define void @check
7 define void @check(i8* %ptr, i1 %bool) {
8 entry:
9   %local = alloca i8, align 1
10 ; CHECK: 1 = MemoryDef(liveOnEntry)
11 ; CHECK-NEXT: store i8 0, i8* %local, align 1
12   store i8 0, i8* %local, align 1
13   br i1 %bool, label %if.then, label %if.end
15 if.then:
16   %p2 = getelementptr inbounds i8, i8* %ptr, i32 1
17 ; CHECK: 2 = MemoryDef(1)
18 ; CHECK-NEXT: store i8 0, i8* %p2, align 1
19   store i8 0, i8* %p2, align 1
20   br label %if.end
22 if.end:
23 ; CHECK: 3 = MemoryPhi({entry,1},{if.then,2})
24 ; NOLIMIT: MemoryUse(1) MayAlias
25 ; NOLIMIT-NEXT: load i8, i8* %local, align 1
26 ; LIMIT: MemoryUse(3)
27 ; LIMIT-NEXT: load i8, i8* %local, align 1
28   load i8, i8* %local, align 1
29   ret void
32 ; CHECK-LABEL: define void @check2
33 define void @check2(i1 %val1, i1 %val2, i1 %val3) {
34 entry:
35   %local = alloca i8, align 1
36   %local2 = alloca i8, align 1
38 ; CHECK: 1 = MemoryDef(liveOnEntry)
39 ; CHECK-NEXT: store i8 0, i8* %local
40   store i8 0, i8* %local
41   br i1 %val1, label %if.then, label %phi.3
43 if.then:
44 ; CHECK: 2 = MemoryDef(1)
45 ; CHECK-NEXT: store i8 2, i8* %local2
46   store i8 2, i8* %local2
47   br i1 %val2, label %phi.2, label %phi.3
49 phi.3:
50 ; CHECK: 7 = MemoryPhi({entry,1},{if.then,2})
51 ; CHECK: 3 = MemoryDef(7)
52 ; CHECK-NEXT: store i8 3, i8* %local2
53   store i8 3, i8* %local2
54   br i1 %val3, label %phi.2, label %phi.1
56 phi.2:
57 ; CHECK: 5 = MemoryPhi({if.then,2},{phi.3,3})
58 ; CHECK: 4 = MemoryDef(5)
59 ; CHECK-NEXT: store i8 4, i8* %local2
60   store i8 4, i8* %local2
61   br label %phi.1
63 phi.1:
64 ; Order matters here; phi.2 needs to come before phi.3, because that's the order
65 ; they're visited in.
66 ; CHECK: 6 = MemoryPhi({phi.2,4},{phi.3,3})
67 ; NOLIMIT: MemoryUse(1) MayAlias
68 ; NOLIMIT-NEXT: load i8, i8* %local
69 ; LIMIT: MemoryUse(6)
70 ; LIMIT-NEXT: load i8, i8* %local
71   load i8, i8* %local
72   ret void
75 ; CHECK-LABEL: define void @cross_phi
76 define void @cross_phi(i8* noalias %p1, i8* noalias %p2) {
77 ; CHECK: 1 = MemoryDef(liveOnEntry)
78 ; CHECK-NEXT: store i8 0, i8* %p1
79   store i8 0, i8* %p1
80 ; NOLIMIT: MemoryUse(1) MustAlias
81 ; NOLIMIT-NEXT: load i8, i8* %p1
82 ; LIMIT: MemoryUse(1)
83 ; LIMIT-NEXT: load i8, i8* %p1
84   load i8, i8* %p1
85   br i1 undef, label %a, label %b
88 ; CHECK: 2 = MemoryDef(1)
89 ; CHECK-NEXT: store i8 0, i8* %p2
90   store i8 0, i8* %p2
91   br i1 undef, label %c, label %d
94 ; CHECK: 3 = MemoryDef(1)
95 ; CHECK-NEXT: store i8 1, i8* %p2
96   store i8 1, i8* %p2
97   br i1 undef, label %c, label %d
100 ; CHECK: 6 = MemoryPhi({a,2},{b,3})
101 ; CHECK: 4 = MemoryDef(6)
102 ; CHECK-NEXT: store i8 2, i8* %p2
103   store i8 2, i8* %p2
104   br label %e
107 ; CHECK: 7 = MemoryPhi({a,2},{b,3})
108 ; CHECK: 5 = MemoryDef(7)
109 ; CHECK-NEXT: store i8 3, i8* %p2
110   store i8 3, i8* %p2
111   br label %e
114 ; 8 = MemoryPhi({c,4},{d,5})
115 ; NOLIMIT: MemoryUse(1) MustAlias
116 ; NOLIMIT-NEXT: load i8, i8* %p1
117 ; LIMIT: MemoryUse(8)
118 ; LIMIT-NEXT: load i8, i8* %p1
119   load i8, i8* %p1
120   ret void
123 ; CHECK-LABEL: define void @looped
124 define void @looped(i8* noalias %p1, i8* noalias %p2) {
125 ; CHECK: 1 = MemoryDef(liveOnEntry)
126 ; CHECK-NEXT: store i8 0, i8* %p1
127   store i8 0, i8* %p1
128   br label %loop.1
130 loop.1:
131 ; CHECK: 6 = MemoryPhi({%0,1},{loop.3,4})
132 ; CHECK: 2 = MemoryDef(6)
133 ; CHECK-NEXT: store i8 0, i8* %p2
134   store i8 0, i8* %p2
135   br i1 undef, label %loop.2, label %loop.3
137 loop.2:
138 ; CHECK: 5 = MemoryPhi({loop.1,2},{loop.3,4})
139 ; CHECK: 3 = MemoryDef(5)
140 ; CHECK-NEXT: store i8 1, i8* %p2
141   store i8 1, i8* %p2
142   br label %loop.3
144 loop.3:
145 ; CHECK: 7 = MemoryPhi({loop.1,2},{loop.2,3})
146 ; CHECK: 4 = MemoryDef(7)
147 ; CHECK-NEXT: store i8 2, i8* %p2
148   store i8 2, i8* %p2
149 ; NOLIMIT: MemoryUse(1) MayAlias
150 ; NOLIMIT-NEXT: load i8, i8* %p1
151 ; LIMIT: MemoryUse(4)
152 ; LIMIT-NEXT: load i8, i8* %p1
153   load i8, i8* %p1
154   br i1 undef, label %loop.2, label %loop.1
157 ; CHECK-LABEL: define void @looped_visitedonlyonce
158 define void @looped_visitedonlyonce(i8* noalias %p1, i8* noalias %p2) {
159   br label %while.cond
161 while.cond:
162 ; CHECK: 5 = MemoryPhi({%0,liveOnEntry},{if.end,3})
163 ; CHECK-NEXT: br i1 undef, label %if.then, label %if.end
164   br i1 undef, label %if.then, label %if.end
166 if.then:
167 ; CHECK: 1 = MemoryDef(5)
168 ; CHECK-NEXT: store i8 0, i8* %p1
169   store i8 0, i8* %p1
170   br i1 undef, label %if.end, label %if.then2
172 if.then2:
173 ; CHECK: 2 = MemoryDef(1)
174 ; CHECK-NEXT: store i8 1, i8* %p2
175   store i8 1, i8* %p2
176   br label %if.end
178 if.end:
179 ; CHECK: 4 = MemoryPhi({while.cond,5},{if.then,1},{if.then2,2})
180 ; CHECK: MemoryUse(4)
181 ; CHECK-NEXT: load i8, i8* %p1
182   load i8, i8* %p1
183 ; CHECK: 3 = MemoryDef(4)
184 ; CHECK-NEXT: store i8 2, i8* %p2
185   store i8 2, i8* %p2
186 ; NOLIMIT: MemoryUse(4) MayAlias
187 ; NOLIMIT-NEXT: load i8, i8* %p1
188 ; LIMIT: MemoryUse(3)
189 ; LIMIT-NEXT: load i8, i8* %p1
190   load i8, i8* %p1
191   br label %while.cond
194 ; CHECK-LABEL: define i32 @use_not_optimized_due_to_backedge
195 define i32 @use_not_optimized_due_to_backedge(i32* nocapture %m_i_strides, i32* nocapture readonly %eval_left_dims) {
196 entry:
197 ; CHECK: 1 = MemoryDef(liveOnEntry)
198 ; CHECK_NEXT: store i32 1, i32* %m_i_strides, align 4
199   store i32 1, i32* %m_i_strides, align 4
200   br label %for.body
202 for.cond.cleanup:                                 ; preds = %for.inc
203   ret i32 %m_i_size.1
205 for.body:                                         ; preds = %entry, %for.inc
206 ; CHECK: 4 = MemoryPhi({entry,1},{for.inc,3})
207 ; CHECK-NEXT: %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
208   %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.inc ]
209   %m_i_size.022 = phi i32 [ 1, %entry ], [ %m_i_size.1, %for.inc ]
210   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
211   %cmp1 = icmp eq i64 %indvars.iv, 0
212   %arrayidx2 = getelementptr inbounds i32, i32* %m_i_strides, i64 %indvars.iv
213 ; CHECK: MemoryUse(4)
214 ; CHECK-NEXT: %0 = load i32, i32* %arrayidx2, align 4
215   %0 = load i32, i32* %arrayidx2, align 4
216   %arrayidx4 = getelementptr inbounds i32, i32* %eval_left_dims, i64 %indvars.iv
217 ; CHECK: MemoryUse(4)
218 ; CHECK-NEXT: %1 = load i32, i32* %arrayidx4, align 4
219   %1 = load i32, i32* %arrayidx4, align 4
220   %mul = mul nsw i32 %1, %0
221   br i1 %cmp1, label %if.then, label %for.inc
223 if.then:                                          ; preds = %for.body
224   %arrayidx7 = getelementptr inbounds i32, i32* %m_i_strides, i64 %indvars.iv.next
225 ; CHECK: 2 = MemoryDef(4)
226 ; CHECK-NEXT: store i32 %mul, i32* %arrayidx7, align 4
227   store i32 %mul, i32* %arrayidx7, align 4
228   br label %for.inc
230 for.inc:                                          ; preds = %for.body, %if.then
231 ; CHECK: 3 = MemoryPhi({for.body,4},{if.then,2})
232 ; CHECK-NEXT: %m_i_size.1 = phi i32 [ %m_i_size.022, %if.then ], [ %mul, %for.body ]
233   %m_i_size.1 = phi i32 [ %m_i_size.022, %if.then ], [ %mul, %for.body ]
234   br i1 %cmp1, label %for.body, label %for.cond.cleanup
238 %ArrayType = type { [2 x i64] }
239 %StructOverArrayType = type { %ArrayType }
240 %BigStruct = type { i8, i8, i8, i8, i8, i8, i8, %ArrayType, %ArrayType}
242 ; CHECK-LABEL: define void @use_not_optimized_due_to_backedge_unknown
243 define void @use_not_optimized_due_to_backedge_unknown(%BigStruct* %this) {
244 entry:
245   %eval_left_dims = alloca %StructOverArrayType, align 8
246   %tmp0 = bitcast %StructOverArrayType* %eval_left_dims to i8*
247   %eval_right_dims = alloca %StructOverArrayType, align 8
248   %tmp1 = bitcast %StructOverArrayType* %eval_right_dims to i8*
249   %lhs_strides = alloca %ArrayType, align 8
250   %rhs_strides = alloca %ArrayType, align 8
251   br label %for.body.preheader
253 for.body.preheader:                               ; preds = %entry
254   %arrayidx.i527 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 7, i32 0, i64 0
255 ; CHECK: 1 = MemoryDef(liveOnEntry)
256 ; CHECK-NEXT: store i64 1, i64* %arrayidx.i527, align 8
257   store i64 1, i64* %arrayidx.i527, align 8
258   %arrayidx.i528 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 8, i32 0, i64 0
259 ; CHECK: 2 = MemoryDef(1)
260 ; CHECK-NEXT: store i64 1, i64* %arrayidx.i528, align 8
261   store i64 1, i64* %arrayidx.i528, align 8
262   br label %for.main.body
264 for.main.body:               ; preds = %if.end220.if.then185_crit_edge, %for.body.preheader
265 ; CHECK: 4 = MemoryPhi({for.body.preheader,2},{if.end220.if.then185_crit_edge,3})
266 ; CHECK-NEXT: %nocontract_idx.0656 = phi i64 [ 0, %for.body.preheader ], [ 1, %if.end220.if.then185_crit_edge ]
267   %nocontract_idx.0656 = phi i64 [ 0, %for.body.preheader ], [ 1, %if.end220.if.then185_crit_edge ]
268   %add199 = add nuw nsw i64 %nocontract_idx.0656, 1
269   %cmp200 = icmp eq i64 %nocontract_idx.0656, 0
270   %arrayidx.i559 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 7, i32 0, i64 %nocontract_idx.0656
271 ; CHECK: MemoryUse(4)
272 ; CHECK-NEXT: %tmp21 = load i64, i64* %arrayidx.i559, align 8
273   %tmp21 = load i64, i64* %arrayidx.i559, align 8
274   %mul206 = mul nsw i64 %tmp21, %tmp21
275   br i1 %cmp200, label %if.end220.if.then185_crit_edge, label %the.end
277 if.end220.if.then185_crit_edge:                   ; preds = %for.main.body
278   %arrayidx.i571 = getelementptr inbounds %BigStruct, %BigStruct* %this, i64 0, i32 7, i32 0, i64 %add199
279 ; CHECK: 3 = MemoryDef(4)
280 ; CHECK-NEXT: store i64 %mul206, i64* %arrayidx.i571, align 8
281   store i64 %mul206, i64* %arrayidx.i571, align 8
282   br label %for.main.body
284 the.end:                            ; preds = %for.main.body
285   ret void
290 @c = local_unnamed_addr global [2 x i16] zeroinitializer, align 2
292 define i32 @dont_merge_noalias_simple(i32* noalias %ptr) {
293 ; CHECK-LABEL: define i32 @dont_merge_noalias_simple
294 ; CHECK-LABEL: entry:
295 ; CHECK:       ; 1 = MemoryDef(liveOnEntry)
296 ; CHECK-NEXT:  store i16 1, i16* %s1.ptr, align 2
298 ; CHECK-LABEL: %for.body
299 ; CHECK:       ; MemoryUse(4)
300 ; CHECK-NEXT:    %lv = load i16, i16* %arrayidx, align 2
302 entry:
303   %s1.ptr = getelementptr inbounds [2 x i16], [2 x i16]* @c, i64 0, i64 0
304   store i16 1, i16* %s1.ptr, align 2
305   br label %for.body
307 for.body:                                         ; preds = %for.body, %entry
308   %storemerge2 = phi i32 [ 1, %entry ], [ %dec, %for.body ]
309   %idxprom1 = zext i32 %storemerge2 to i64
310   %arrayidx = getelementptr inbounds [2 x i16], [2 x i16]* @c, i64 0, i64 %idxprom1
311   %lv = load i16, i16* %arrayidx, align 2
312   %conv = sext i16 %lv to i32
313   store i32 %conv, i32* %ptr, align 4
314   %dec = add nsw i32 %storemerge2, -1
315   %cmp = icmp sgt i32 %storemerge2, 0
316   br i1 %cmp, label %for.body, label %for.end
318 for.end:                                          ; preds = %for.body
319   %s2.ptr = getelementptr inbounds [2 x i16], [2 x i16]* @c, i64 0, i64 0
320   store i16 0, i16* %s2.ptr, align 2
321   ret i32 0
325 define i32 @dont_merge_noalias_complex(i32* noalias %ptr, i32* noalias %another) {
326 ; CHECK-LABEL: define i32 @dont_merge_noalias_complex
327 ; CHECK-LABEL: entry:
328 ; CHECK:       ; 1 = MemoryDef(liveOnEntry)
329 ; CHECK-NEXT:  store i16 1, i16* %s1.ptr, align 2
331 ; CHECK-LABEL: %for.body
332 ; CHECK:       ; MemoryUse(7)
333 ; CHECK-NEXT:    %lv = load i16, i16* %arrayidx, align 2
335 entry:
336   %s1.ptr = getelementptr inbounds [2 x i16], [2 x i16]* @c, i64 0, i64 0
337   store i16 1, i16* %s1.ptr, align 2
338   br label %for.body
340 for.body:                                         ; preds = %for.body, %entry
341   %storemerge2 = phi i32 [ 1, %entry ], [ %dec, %merge.body ]
342   %idxprom1 = zext i32 %storemerge2 to i64
343   %arrayidx = getelementptr inbounds [2 x i16], [2 x i16]* @c, i64 0, i64 %idxprom1
344   %lv = load i16, i16* %arrayidx, align 2
345   %conv = sext i16 %lv to i32
346   store i32 %conv, i32* %ptr, align 4
347   %dec = add nsw i32 %storemerge2, -1
349   %cmpif = icmp sgt i32 %storemerge2, 1
350   br i1 %cmpif, label %if.body, label %else.body
352 if.body:
353   store i32 %conv, i32* %another, align 4
354   br label %merge.body
356 else.body:
357   store i32 %conv, i32* %another, align 4
358   br label %merge.body
360 merge.body:
361   %cmp = icmp sgt i32 %storemerge2, 0
362   br i1 %cmp, label %for.body, label %for.end
364 for.end:                                          ; preds = %for.body
365   %s2.ptr = getelementptr inbounds [2 x i16], [2 x i16]* @c, i64 0, i64 0
366   store i16 0, i16* %s2.ptr, align 2
367   ret i32 0
370 declare i1 @should_exit(i32) readnone
371 declare void @init([32 x i32]*)
373 ; Test case for PR47498.
374 ; %l.1 may read the result of `store i32 10, i32* %p.1` in %storebb, because
375 ; after %storebb has been executed, %loop.1.header might be executed again.
376 ; Make sure %l.1's defining access is the MemoryPhi in the block.
377 define void @dont_merge_noalias_complex_2(i32 %arg, i32 %arg1)  {
378 ; CHECK-LABEL: define void @dont_merge_noalias_complex_2(
380 ; CHECK-LABEL: entry:
381 ; CHECK:       ; 1 = MemoryDef(liveOnEntry)
382 ; CHECK-NEXT:  call void @init([32 x i32]* %tmp)
384 ; CHECK-LABEL: loop.1.header:
385 ; CHECK-NEXT:  ; 4 = MemoryPhi({entry,1},{loop.1.latch,3})
386 ; CHECK:       ; MemoryUse(4)
387 ; CHECK-NEXT:  %l.1 = load i32, i32* %p.1, align 4
389 ; CHECK-LABEL: loop.1.latch:
390 ; CHECK-NEXT:  ; 3 = MemoryPhi({loop.1.header,4},{storebb,2})
392 ; CHECK-LABEL: storebb:
393 ; CHECK-NEXT:  %iv.add2 = add nuw nsw i64 %iv, 2
394 ; CHECK-NEXT:  %p.2 = getelementptr inbounds [32 x i32], [32 x i32]* %tmp, i64 0, i64 %iv.add2
395 ; CHECK-NEXT:  ; MemoryUse(4)
396 ; CHECK-NEXT:  %l.2 = load i32, i32* %p.2, align 4
397 ; CHECK-NEXT:  ; 2 = MemoryDef(4)
398 ; CHECK-NEXT:  store i32 10, i32* %p.1, align 4
399 entry:
400   %tmp = alloca [32 x i32], align 16
401   call void @init([32 x i32]* %tmp)
402   br label %loop.1.header
404 loop.1.header:
405   %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.1.latch ]
406   %iv.next = add nuw nsw i64 %iv, 1
407   %p.1 = getelementptr inbounds [32 x i32], [32 x i32]* %tmp, i64 0, i64 %iv.next
408   %l.1 = load i32, i32* %p.1, align 4
409   %tmp244 = icmp ult i64 %iv, 10
410   br i1 %tmp244, label %loop.1.latch, label %storebb
412 loop.1.latch:
413   %ec = call i1 @should_exit(i32 %l.1)
414   br i1 %ec, label %exit, label %loop.1.header
416 storebb:
417   %iv.add2 = add nuw nsw i64 %iv, 2
418   %p.2 = getelementptr inbounds [32 x i32], [32 x i32]* %tmp, i64 0, i64 %iv.add2
419   %l.2 = load i32, i32* %p.2, align 4
420   store i32 10, i32* %p.1, align 4
421   br label %loop.1.latch
423 exit:
424   ret void
427 ; CHECK-LABEL: define void @use_clobbered_by_def_in_loop()
428 define void @use_clobbered_by_def_in_loop() {
429 entry:
430   %nodeStack = alloca [12 x i32], align 4
431   %0 = bitcast [12 x i32]* %nodeStack to i8*
432   call void @llvm.lifetime.start.p0i8(i64 48, i8* nonnull %0)
433   br i1 false, label %cleanup, label %while.cond
435 ; CHECK-LABEL: while.cond:
436 ; CHECK-NEXT: ; [[NO6:.*]] = MemoryPhi({entry,1},{while.cond.backedge,5})
438 while.cond:                                       ; preds = %entry, %while.cond.backedge
439   %depth.1 = phi i32 [ %depth.1.be, %while.cond.backedge ], [ 0, %entry ]
440   %cmp = icmp sgt i32 %depth.1, 0
441   br i1 %cmp, label %land.rhs, label %while.end
443 ; CHECK-LABEL: land.rhs:
444 ; CHECK-NEXT: %sub = add nsw i32 %depth.1, -1
445 ; CHECK-NEXT: %arrayidx = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %sub
446 ; CHECK-NEXT: ; MemoryUse([[NO6]])
447 ; CHECK-NEXT: %1 = load i32, i32* %arrayidx, align 4
449 land.rhs:                                         ; preds = %while.cond
450   %sub = add nsw i32 %depth.1, -1
451   %arrayidx = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %sub
452   %1 = load i32, i32* %arrayidx, align 4
453   br i1 true, label %while.body, label %while.end
455 while.body:                                       ; preds = %land.rhs
456   br i1 true, label %cleanup, label %while.cond.backedge
458 while.cond.backedge:                              ; preds = %while.body, %while.end
459   %depth.1.be = phi i32 [ %sub, %while.body ], [ %inc, %while.end ]
460   br label %while.cond
462 while.end:                                        ; preds = %while.cond, %land.rhs
463   %arrayidx10 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %depth.1
464   store i32 %depth.1, i32* %arrayidx10, align 4
465   %inc = add nsw i32 %depth.1, 1
466   br i1 true, label %cleanup, label %while.cond.backedge
468 cleanup:                                          ; preds = %while.body, %while.end, %entry
469   call void @llvm.lifetime.end.p0i8(i64 48, i8* nonnull %0)
470   ret void
473 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
474 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
476 define void @another_loop_clobber_inc() {
477 ; CHECK-LABEL: void @another_loop_clobber_inc
478 ; CHECK-LABEL: loop.header:
479 ; CHECK-NEXT:  ; 4 = MemoryPhi({entry,1},{cond.read,3})
481 ; CHECK-LABEL: cond.read:
482 ; CHECK:       ; MemoryUse(4)
483 ; CHECK-NEXT:  %use = load i32, i32* %ptr.1, align 4
484 ; CHECK-NEXT:  ; 2 = MemoryDef(4)
485 ; CHECK-NEXT:  %c.2 = call i1 @cond(i32 %use)
486 ; CHECK-NEXT:  %ptr.10 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %inc
487 ; CHECK-NEXT:  ; 3 = MemoryDef(2)
488 ; CHECK-NEXT:  store i32 10, i32* %ptr.2, align 4
490 entry:
491   %nodeStack = alloca [12 x i32], align 4
492   %c.1 = call i1 @cond(i32 1)
493   br i1 %c.1, label %cleanup, label %loop.header
495 loop.header:                                       ; preds = %entry, %while.cond.backedge
496   %depth.1 = phi i32 [ %inc, %cond.read], [ 1, %entry ]
497   %cmp = icmp sgt i32 %depth.1, 0
498   %inc = add nsw i32 %depth.1, 3
499   %inc2 = add nsw i32 %depth.1, 6
500   br i1 %cmp, label %cond.read, label %cleanup
502 cond.read:                                        ; preds = %while.cond
503   %ptr.1 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %depth.1
504   %ptr.2 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %inc2
505   %use = load i32, i32* %ptr.1, align 4
506   %c.2 = call i1 @cond(i32 %use)
507   %ptr.10 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i32 %inc
508   store i32 10, i32* %ptr.2, align 4
509   br i1 %c.2, label %loop.header, label %cleanup
511 cleanup:
512   ret void
515 define void @another_loop_clobber_dec() {
516 ; CHECK-LABEL: void @another_loop_clobber_dec
517 ; CHECK-LABEL: loop.header:
518 ; CHECK-NEXT:  ; 4 = MemoryPhi({entry,1},{cond.read,3})
520 ; CHECK-LABEL: cond.read:
521 ; CHECK:       ; MemoryUse(4)
522 ; CHECK-NEXT:  %use = load i32, i32* %ptr.1, align 4
523 ; CHECK-NEXT:  ; 2 = MemoryDef(4)
524 ; CHECK-NEXT:  %c.2 = call i1 @cond(i32 %use)
525 ; CHECK-NEXT:  %ptr.10 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i64 %sub
526 ; CHECK-NEXT:  ; 3 = MemoryDef(2)
527 ; CHECK-NEXT:  store i32 10, i32* %ptr.2, align 4
529 entry:
530   %nodeStack = alloca [12 x i32], align 4
531   %c.1 = call i1 @cond(i32 1)
532   br i1 %c.1, label %cleanup, label %loop.header
534 loop.header:                                       ; preds = %entry, %while.cond.backedge
535   %depth.1 = phi i64 [ %sub, %cond.read], [ 20, %entry ]
536   %cmp = icmp sgt i64 %depth.1, 6
537   %sub = sub nsw nuw i64 %depth.1, 3
538   %sub2 = sub nsw nuw i64 %depth.1, 6
539   br i1 %cmp, label %cond.read, label %cleanup
541 cond.read:                                        ; preds = %while.cond
542   %ptr.1 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i64 %depth.1
543   %ptr.2 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i64 %sub2
544   %use = load i32, i32* %ptr.1, align 4
545   %c.2 = call i1 @cond(i32 %use)
546   %ptr.10 = getelementptr inbounds [12 x i32], [12 x i32]* %nodeStack, i32 0, i64 %sub
547   store i32 10, i32* %ptr.2, align 4
548   br i1 %c.2, label %loop.header, label %cleanup
550 cleanup:
551   ret void
554 declare i1 @cond(i32)