1; RUN: opt -passes='print<stack-lifetime><may>' -disable-output %s 2>&1 | FileCheck %s --check-prefixes=CHECK,MAY
2; RUN: opt -passes='print<stack-lifetime><must>' -disable-output %s 2>&1 | FileCheck %s --check-prefixes=CHECK,MUST
3
4define void @f() {
5; CHECK-LABEL: define void @f()
6entry:
7; CHECK: entry:
8; CHECK-NEXT: Alive: <>
9  %x = alloca i32, align 4
10  %y = alloca i32, align 4
11; CHECK: %y = alloca i32, align 4
12; CHECK-NEXT: Alive: <>
13  %z = alloca i32, align 4
14  %x0 = bitcast i32* %x to i8*
15  %y0 = bitcast i32* %y to i8*
16  %z0 = bitcast i32* %z to i8*
17  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %z0)
18; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %z0)
19; CHECK-NEXT: Alive: <z>
20
21  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
22; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
23; CHECK-NEXT: Alive: <x z>
24
25  call void @capture32(i32* %x)
26  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
27; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
28; CHECK-NEXT: Alive: <z>
29
30  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
31; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
32; CHECK-NEXT: Alive: <y z>
33
34  call void @capture32(i32* %y)
35  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
36; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
37; CHECK-NEXT: Alive: <z>
38
39  call void @capture32(i32* %z)
40  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %z0)
41; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %z0)
42; CHECK-NEXT: Alive: <>
43
44  ret void
45}
46
47define void @no_markers() {
48; CHECK-LABEL: define void @no_markers()
49entry:
50; CHECK: entry:
51; CHECK-NEXT: Alive: <y>
52  %x = alloca i32, align 4
53  %y = alloca i32, align 4
54  %x0 = bitcast i32* %x to i8*
55  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
56; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
57; CHECK-NEXT: Alive: <x y>
58
59  call void @capture32(i32* %x)
60  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
61; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
62; CHECK-NEXT: Alive: <y>
63
64  call void @capture32(i32* %y)
65  ret void
66}
67
68define void @g() {
69; CHECK-LABEL: define void @g()
70entry:
71; CHECK: entry:
72; CHECK-NEXT: Alive: <>
73  %x = alloca i32, align 4
74  %y = alloca i32, align 4
75  %z = alloca i64, align 4
76  %x0 = bitcast i32* %x to i8*
77  %y0 = bitcast i32* %y to i8*
78  %z0 = bitcast i64* %z to i8*
79  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
80; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
81; CHECK-NEXT: Alive: <x>
82
83  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
84; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
85; CHECK-NEXT: Alive: <x y>
86
87  call void @capture32(i32* %x)
88  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
89; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
90; CHECK-NEXT: Alive: <y>
91
92  call void @capture32(i32* %y)
93  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
94; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
95; CHECK-NEXT: Alive: <>
96
97  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %z0)
98; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %z0)
99; CHECK-NEXT: Alive: <z>
100
101  call void @capture64(i64* %z)
102  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %z0)
103; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %z0)
104; CHECK-NEXT: Alive: <>
105
106  ret void
107; CHECK: ret void
108; CHECK-NEXT: Alive: <>
109}
110
111define void @h() {
112; CHECK-LABEL: define void @h()
113entry:
114; CHECK: entry:
115; CHECK-NEXT: Alive: <>
116  %x = alloca i32, align 16
117; CHECK: %x = alloca i32, align 16
118; CHECK-NEXT: Alive: <>
119  %z = alloca i64, align 4
120  %y = alloca i32, align 4
121  %x0 = bitcast i32* %x to i8*
122  %y0 = bitcast i32* %y to i8*
123  %z0 = bitcast i64* %z to i8*
124  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
125; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
126; CHECK-NEXT: Alive: <x>
127
128  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
129; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
130; CHECK-NEXT: Alive: <x y>
131
132  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %z0)
133; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %z0)
134; CHECK-NEXT: Alive: <x y z>
135
136  call void @capture32(i32* %x)
137  call void @capture32(i32* %y)
138  call void @capture64(i64* %z)
139  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
140; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
141; CHECK-NEXT: Alive: <y z>
142
143  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
144; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
145; CHECK-NEXT: Alive: <z>
146
147  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %z0)
148; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %z0)
149; CHECK-NEXT: Alive: <>
150
151  ret void
152}
153
154define void @i(i1 zeroext %a, i1 zeroext %b) {
155; CHECK-LABEL: define void @i(i1 zeroext %a, i1 zeroext %b)
156entry:
157; CHECK: entry:
158; CHECK-NEXT: Alive: <>
159  %x1 = alloca i64, align 8
160  %x2 = alloca i64, align 8
161  %y = alloca i64, align 8
162  %y1 = alloca i64, align 8
163  %y2 = alloca i64, align 8
164  %z = alloca i64, align 8
165  %z1 = alloca i64, align 8
166  %z2 = alloca i64, align 8
167  %0 = bitcast i64* %x1 to i8*
168  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %0)
169; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %0)
170; CHECK-NEXT: Alive: <x1>
171
172  %1 = bitcast i64* %x2 to i8*
173  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %1)
174; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %1)
175; CHECK-NEXT: Alive: <x1 x2>
176
177  call void @capture64(i64* nonnull %x1)
178  call void @capture64(i64* nonnull %x2)
179  br i1 %a, label %if.then, label %if.else4
180; CHECK: br i1 %a, label %if.then, label %if.else4
181; CHECK-NEXT: Alive: <x1 x2>
182
183if.then:                                          ; preds = %entry
184; CHECK: if.then:
185; CHECK-NEXT: Alive: <x1 x2>
186  %2 = bitcast i64* %y to i8*
187  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %2)
188; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %2)
189; CHECK-NEXT: Alive: <x1 x2 y>
190
191  call void @capture64(i64* nonnull %y)
192  br i1 %b, label %if.then3, label %if.else
193
194if.then3:                                         ; preds = %if.then
195; CHECK: if.then3:
196; CHECK-NEXT: Alive: <x1 x2 y>
197  %3 = bitcast i64* %y1 to i8*
198  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %3)
199; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %3)
200; CHECK-NEXT: Alive: <x1 x2 y y1>
201
202  call void @capture64(i64* nonnull %y1)
203  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %3)
204; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %3)
205; CHECK-NEXT: Alive: <x1 x2 y>
206
207  br label %if.end
208
209if.else:                                          ; preds = %if.then
210; CHECK: if.else:
211; CHECK-NEXT: Alive: <x1 x2 y>
212  %4 = bitcast i64* %y2 to i8*
213  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %4)
214; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %4)
215; CHECK-NEXT: Alive: <x1 x2 y y2>
216
217  call void @capture64(i64* nonnull %y2)
218  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %4)
219; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %4)
220; CHECK-NEXT: Alive: <x1 x2 y>
221
222  br label %if.end
223
224if.end:                                           ; preds = %if.else, %if.then3
225; CHECK: if.end:
226; CHECK-NEXT: Alive: <x1 x2 y>
227  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %2)
228; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %2)
229; CHECK-NEXT: Alive: <x1 x2>
230
231  br label %if.end9
232
233if.else4:                                         ; preds = %entry
234; CHECK: if.else4:
235; CHECK-NEXT: Alive: <x1 x2>
236
237  %5 = bitcast i64* %z to i8*
238; CHECK: %5 = bitcast i64* %z to i8*
239; CHECK-NEXT: Alive: <x1 x2>
240
241  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %5)
242; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %5)
243; CHECK-NEXT: Alive: <x1 x2 z>
244
245  call void @capture64(i64* nonnull %z)
246  br i1 %b, label %if.then6, label %if.else7
247
248if.then6:                                         ; preds = %if.else4
249; CHECK: if.then6:
250; CHECK-NEXT: Alive: <x1 x2 z>
251  %6 = bitcast i64* %z1 to i8*
252  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %6)
253; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %6)
254; CHECK-NEXT: Alive: <x1 x2 z z1>
255
256  call void @capture64(i64* nonnull %z1)
257  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %6)
258; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %6)
259; CHECK-NEXT: Alive: <x1 x2 z>
260
261  br label %if.end8
262
263if.else7:                                         ; preds = %if.else4
264; CHECK: if.else7:
265; CHECK-NEXT: Alive: <x1 x2 z>
266  %7 = bitcast i64* %z2 to i8*
267  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %7)
268; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %7)
269; CHECK-NEXT: Alive: <x1 x2 z z2>
270
271  call void @capture64(i64* nonnull %z2)
272  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %7)
273; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %7)
274; CHECK-NEXT: Alive: <x1 x2 z>
275
276  br label %if.end8
277
278if.end8:                                          ; preds = %if.else7, %if.then6
279; CHECK: if.end8:
280; CHECK-NEXT: Alive: <x1 x2 z>
281  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %5)
282; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %5)
283; CHECK-NEXT: Alive: <x1 x2>
284
285  br label %if.end9
286
287if.end9:                                          ; preds = %if.end8, %if.end
288; CHECK: if.end9:
289; CHECK-NEXT: Alive: <x1 x2>
290  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %1)
291; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %1)
292; CHECK-NEXT: Alive: <x1>
293
294  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %0)
295; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %0)
296; CHECK-NEXT: Alive: <>
297
298  ret void
299}
300
301define void @no_merge1(i1 %d) {
302; CHECK-LABEL: define void @no_merge1(i1 %d)
303entry:
304; CHECK: entry:
305; CHECK-NEXT: Alive: <>
306  %x = alloca i32, align 4
307  %y = alloca i32, align 4
308  %x0 = bitcast i32* %x to i8*
309  %y0 = bitcast i32* %y to i8*
310  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
311; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
312; CHECK-NEXT: Alive: <x>
313
314  call void @capture32(i32* %x)
315  br i1 %d, label %bb2, label %bb3
316
317bb2:                                              ; preds = %entry
318; CHECK: bb2:
319; CHECK-NEXT: Alive: <x>
320  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
321; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
322; CHECK-NEXT: Alive: <x y>
323
324  call void @capture32(i32* %y)
325  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
326; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
327; CHECK-NEXT: Alive: <x>
328
329  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
330; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
331; CHECK-NEXT: Alive: <>
332
333  ret void
334
335bb3:                                              ; preds = %entry
336; CHECK: bb3:
337; CHECK-NEXT: Alive: <x>
338  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
339; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
340; CHECK-NEXT: Alive: <>
341
342  ret void
343}
344
345define void @merge1(i1 %d) {
346; CHECK-LABEL: define void @merge1(i1 %d)
347entry:
348; CHECK: entry:
349; CHECK-NEXT: Alive: <>
350  %x = alloca i32, align 4
351  %y = alloca i32, align 4
352  %x0 = bitcast i32* %x to i8*
353  %y0 = bitcast i32* %y to i8*
354  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
355; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
356; CHECK-NEXT: Alive: <x>
357
358  call void @capture32(i32* %x)
359  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
360; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
361; CHECK-NEXT: Alive: <>
362
363  br i1 %d, label %bb2, label %bb3
364
365bb2:                                              ; preds = %entry
366; CHECK: bb2:
367; CHECK-NEXT: Alive: <>
368  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
369; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
370; CHECK-NEXT: Alive: <y>
371
372  call void @capture32(i32* %y)
373  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
374; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
375; CHECK-NEXT: Alive: <>
376
377  ret void
378
379bb3:                                              ; preds = %entry
380; CHECK: bb3:
381; CHECK-NEXT: Alive: <>
382  ret void
383}
384
385define void @merge2_noend(i1 %d) {
386; CHECK-LABEL: define void @merge2_noend(i1 %d)
387entry:
388; CHECK: entry:
389; CHECK-NEXT: Alive: <>
390  %x = alloca i32, align 4
391  %y = alloca i32, align 4
392  %x0 = bitcast i32* %x to i8*
393  %y0 = bitcast i32* %y to i8*
394  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
395; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
396; CHECK-NEXT: Alive: <x>
397
398  call void @capture32(i32* %x)
399  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
400; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
401; CHECK-NEXT: Alive: <>
402
403  br i1 %d, label %bb2, label %bb3
404
405bb2:                                              ; preds = %entry
406; CHECK: bb2:
407; CHECK-NEXT: Alive: <>
408  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
409; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
410; CHECK-NEXT: Alive: <y>
411
412  call void @capture32(i32* %y)
413  ret void
414
415bb3:                                              ; preds = %entry
416; CHECK: bb3:
417; CHECK-NEXT: Alive: <>
418  ret void
419}
420
421define void @merge3_noend(i1 %d) {
422; CHECK-LABEL: define void @merge3_noend(i1 %d)
423entry:
424; CHECK: entry:
425; CHECK-NEXT: Alive: <>
426  %x = alloca i32, align 4
427  %y = alloca i32, align 4
428  %x0 = bitcast i32* %x to i8*
429  %y0 = bitcast i32* %y to i8*
430  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
431; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
432; CHECK-NEXT: Alive: <x>
433
434  call void @capture32(i32* %x)
435  br i1 %d, label %bb2, label %bb3
436
437bb2:                                              ; preds = %entry
438; CHECK: bb2:
439; CHECK-NEXT: Alive: <x>
440  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
441; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
442; CHECK-NEXT: Alive: <>
443
444  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
445; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
446; CHECK-NEXT: Alive: <y>
447
448  call void @capture32(i32* %y)
449  ret void
450
451bb3:                                              ; preds = %entry
452; CHECK: bb3:
453; CHECK-NEXT: Alive: <x>
454  ret void
455}
456
457define void @nomerge4_nostart(i1 %d) {
458; CHECK-LABEL: define void @nomerge4_nostart(i1 %d)
459entry:
460; CHECK: entry:
461; CHECK-NEXT: Alive: <x>
462  %x = alloca i32, align 4
463  %y = alloca i32, align 4
464  %x0 = bitcast i32* %x to i8*
465  %y0 = bitcast i32* %y to i8*
466  call void @capture32(i32* %x)
467  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
468; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
469; CHECK-NEXT: Alive: <x>
470
471  br i1 %d, label %bb2, label %bb3
472
473bb2:                                              ; preds = %entry
474; CHECK: bb2:
475; CHECK-NEXT: Alive: <x>
476  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
477; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
478; CHECK-NEXT: Alive: <x y>
479
480  call void @capture32(i32* %y)
481  ret void
482
483bb3:                                              ; preds = %entry
484; CHECK: bb3:
485; CHECK-NEXT: Alive: <x>
486  ret void
487}
488
489define void @array_merge() {
490; CHECK-LABEL: define void @array_merge()
491entry:
492; CHECK: entry:
493; CHECK-NEXT: Alive: <>
494  %A.i1 = alloca [100 x i32], align 4
495  %B.i2 = alloca [100 x i32], align 4
496  %A.i = alloca [100 x i32], align 4
497  %B.i = alloca [100 x i32], align 4
498  %0 = bitcast [100 x i32]* %A.i to i8*
499  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %0)
500; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %0)
501; CHECK-NEXT: Alive: <A.i>
502
503  %1 = bitcast [100 x i32]* %B.i to i8*
504  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %1)
505; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %1)
506; CHECK-NEXT: Alive: <A.i B.i>
507
508  call void @capture100x32([100 x i32]* %A.i)
509; CHECK: call void @capture100x32([100 x i32]* %A.i)
510; CHECK-NEXT: Alive: <A.i B.i>
511
512  call void @capture100x32([100 x i32]* %B.i)
513  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %0)
514; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %0)
515; CHECK-NEXT: Alive: <B.i>
516
517  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %1)
518; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %1)
519; CHECK-NEXT: Alive: <>
520
521  %2 = bitcast [100 x i32]* %A.i1 to i8*
522  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %2)
523; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %2)
524; CHECK-NEXT: Alive: <A.i1>
525
526  %3 = bitcast [100 x i32]* %B.i2 to i8*
527  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %3)
528; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %3)
529; CHECK-NEXT: Alive: <A.i1 B.i2>
530
531  call void @capture100x32([100 x i32]* %A.i1)
532  call void @capture100x32([100 x i32]* %B.i2)
533  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %2)
534; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %2)
535; CHECK-NEXT: Alive: <B.i2>
536
537  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %3)
538; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %3)
539; CHECK-NEXT: Alive: <>
540
541  ret void
542}
543
544define void @myCall_pr15707() {
545; CHECK-LABEL: define void @myCall_pr15707()
546entry:
547; CHECK: entry:
548; CHECK-NEXT: Alive: <>
549  %buf1 = alloca i8, i32 100000, align 16
550  %buf2 = alloca i8, i32 100000, align 16
551  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %buf1)
552; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %buf1)
553; CHECK-NEXT: Alive: <buf1>
554
555  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %buf1)
556; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %buf1)
557; CHECK-NEXT: Alive: <>
558
559  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %buf1)
560; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %buf1)
561; CHECK-NEXT: Alive: <buf1>
562
563  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %buf2)
564; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %buf2)
565; CHECK-NEXT: Alive: <buf1 buf2>
566
567  call void @capture8(i8* %buf1)
568  call void @capture8(i8* %buf2)
569  ret void
570}
571
572define void @bad_range() {
573; CHECK-LABEL: define void @bad_range()
574entry:
575; CHECK: entry:
576; CHECK-NEXT: Alive: <A.i1 B.i2>
577  %A.i1 = alloca [100 x i32], align 4
578  %B.i2 = alloca [100 x i32], align 4
579  %A.i = alloca [100 x i32], align 4
580  %B.i = alloca [100 x i32], align 4
581  %0 = bitcast [100 x i32]* %A.i to i8*
582  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %0)
583; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %0)
584; CHECK-NEXT: Alive: <A.i A.i1 B.i2>
585
586  %1 = bitcast [100 x i32]* %B.i to i8*
587  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %1)
588; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %1)
589; CHECK-NEXT: Alive: <A.i A.i1 B.i B.i2>
590
591  call void @capture100x32([100 x i32]* %A.i)
592  call void @capture100x32([100 x i32]* %B.i)
593  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %0)
594; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %0)
595; CHECK-NEXT: Alive: <A.i1 B.i B.i2>
596
597  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %1)
598; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %1)
599; CHECK-NEXT: Alive: <A.i1 B.i2>
600
601  br label %block2
602
603block2:                                           ; preds = %entry
604; CHECK: block2:
605; CHECK-NEXT: Alive: <A.i1 B.i2>
606  call void @capture100x32([100 x i32]* %A.i)
607  call void @capture100x32([100 x i32]* %B.i)
608  ret void
609}
610
611%struct.Klass = type { i32, i32 }
612
613define i32 @shady_range(i32 %argc, i8** nocapture %argv) {
614; CHECK-LABEL: define i32 @shady_range(i32 %argc, i8** nocapture %argv)
615entry:
616; CHECK: entry:
617; CHECK-NEXT: Alive: <>
618  %a.i = alloca [4 x %struct.Klass], align 16
619  %b.i = alloca [4 x %struct.Klass], align 16
620  %a8 = bitcast [4 x %struct.Klass]* %a.i to i8*
621  %b8 = bitcast [4 x %struct.Klass]* %b.i to i8*
622  %z2 = getelementptr inbounds [4 x %struct.Klass], [4 x %struct.Klass]* %a.i, i64 0, i64 0, i32 0
623  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %a8)
624; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %a8)
625; CHECK-NEXT: Alive: <a.i>
626
627  call void @llvm.lifetime.start.p0i8(i64 -1, i8* %b8)
628; CHECK: call void @llvm.lifetime.start.p0i8(i64 -1, i8* %b8)
629; CHECK-NEXT: Alive: <a.i b.i>
630
631  call void @capture8(i8* %a8)
632  call void @capture8(i8* %b8)
633  %z3 = load i32, i32* %z2, align 16
634  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %a8)
635; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %a8)
636; CHECK-NEXT: Alive: <b.i>
637
638  call void @llvm.lifetime.end.p0i8(i64 -1, i8* %b8)
639; CHECK: call void @llvm.lifetime.end.p0i8(i64 -1, i8* %b8)
640; CHECK-NEXT: Alive: <>
641
642  ret i32 %z3
643}
644
645define void @end_loop() {
646; CHECK-LABEL: define void @end_loop()
647entry:
648; CHECK: entry:
649; CHECK-NEXT: Alive: <>
650  %x = alloca i8, align 4
651  call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
652; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
653; CHECK-NEXT: Alive: <x>
654
655  br label %l2
656
657l2:                                               ; preds = %l2, %entry
658; CHECK: l2:
659; MAY-NEXT: Alive: <x>
660; MUST-NEXT: Alive: <>
661  call void @capture8(i8* %x)
662  call void @llvm.lifetime.end.p0i8(i64 1, i8* %x)
663; CHECK: call void @llvm.lifetime.end.p0i8(i64 1, i8* %x)
664; CHECK-NEXT: Alive: <>
665
666  br label %l2
667}
668
669define void @start_loop() {
670; CHECK-LABEL: define void @start_loop()
671entry:
672; CHECK: entry:
673; CHECK-NEXT: Alive: <>
674  %x = alloca i8, align 4
675  %y = alloca i8, align 4
676  call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
677; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
678; CHECK-NEXT: Alive: <x>
679
680  br label %l2
681
682l2:                                               ; preds = %l2, %entry
683; CHECK: l2:
684; CHECK-NEXT: Alive: <x>
685  call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
686; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
687; CHECK-NEXT: Alive: <x y>
688
689  call void @capture8(i8* %y)
690  call void @llvm.lifetime.end.p0i8(i64 1, i8* %y)
691; CHECK: call void @llvm.lifetime.end.p0i8(i64 1, i8* %y)
692; CHECK-NEXT: Alive: <x>
693
694  call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
695; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
696; CHECK-NEXT: Alive: <x>
697
698  call void @capture8(i8* %x)
699  br label %l2
700}
701
702%struct.char_array = type { [500 x i8] }
703
704define dso_local void @gep_test(i32 %cond)  {
705; CHECK-LABEL: define dso_local void @gep_test
706entry:
707; CHECK: entry:
708; CHECK-NEXT: Alive: <>
709  %a = alloca %struct.char_array, align 8
710  %b = alloca %struct.char_array, align 8
711  %tobool.not = icmp eq i32 %cond, 0
712  br i1 %tobool.not, label %if.else, label %if.then
713
714if.then:                                          ; preds = %entry
715; CHECK: if.then:
716; CHECK-NEXT: Alive: <>
717  %0 = getelementptr inbounds %struct.char_array, %struct.char_array* %a, i64 0, i32 0, i64 0
718  call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %0)
719; CHECK: call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %0)
720; CHECK-NEXT: Alive: <a>
721  tail call void @capture8(i8* %0)
722  call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %0)
723; CHECK: call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %0)
724; CHECK-NEXT: Alive: <>
725  br label %if.end
726
727if.else:                                          ; preds = %entry
728; CHECK: if.else:
729; CHECK-NEXT: Alive: <>
730  %1 = getelementptr inbounds %struct.char_array, %struct.char_array* %b, i64 0, i32 0, i64 0
731  call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %1)
732; CHECK: call void @llvm.lifetime.start.p0i8(i64 500, i8* nonnull %1)
733; CHECK-NEXT: Alive: <b>
734  tail call void @capture8(i8* %1)
735  call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %1)
736; CHECK: call void @llvm.lifetime.end.p0i8(i64 500, i8* nonnull %1)
737; CHECK-NEXT: Alive: <>
738  br label %if.end
739
740if.end:                                           ; preds = %if.else, %if.then
741; CHECK: if.end:
742; CHECK-NEXT: Alive: <>
743  ret void
744}
745
746define void @if_must(i1 %a) {
747; CHECK-LABEL: define void @if_must
748entry:
749; CHECK: entry:
750; CHECK-NEXT: Alive: <>
751  %x = alloca i8, align 4
752  %y = alloca i8, align 4
753
754  br i1 %a, label %if.then, label %if.else
755; CHECK: br i1 %a, label %if.then, label %if.else
756; CHECK-NEXT: Alive: <>
757
758if.then:
759; CHECK: if.then:
760; CHECK-NEXT: Alive: <>
761  call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
762; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
763; CHECK-NEXT: Alive: <y>
764
765  br label %if.end
766; CHECK: br label %if.end
767; CHECK-NEXT: Alive: <y>
768
769if.else:
770; CHECK: if.else:
771; CHECK-NEXT: Alive: <>
772  call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
773; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
774; CHECK-NEXT: Alive: <y>
775
776  call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
777; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
778; CHECK-NEXT: Alive: <x y>
779
780  br label %if.end
781; CHECK: br label %if.end
782; CHECK-NEXT: Alive: <x y>
783
784if.end:
785; CHECK: if.end:
786; MAY-NEXT: Alive: <x y>
787; MUST-NEXT: Alive: <y>
788
789  ret void
790}
791
792define void @unreachable() {
793; CHECK-LABEL: define void @unreachable
794entry:
795; CHECK: entry:
796; CHECK-NEXT: Alive: <>
797  %x = alloca i8, align 4
798  %y = alloca i8, align 4
799
800  call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
801; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %y)
802; CHECK-NEXT: Alive: <y>
803
804  call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
805; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
806; CHECK-NEXT: Alive: <x y>
807
808  br label %end
809; CHECK: br label %end
810; CHECK-NEXT: Alive: <x y>
811
812dead:
813; CHECK: dead:
814; CHECK-NOT: Alive:
815  call void @llvm.lifetime.start.p0i8(i64 4, i8* %y)
816
817  br label %end
818; CHECK: br label %end
819; CHECK-NOT: Alive:
820
821end:
822; CHECK: end:
823; CHECK-NEXT: Alive: <x y>
824
825  ret void
826}
827
828define void @non_alloca(i8* %p) {
829; CHECK-LABEL: define void @non_alloca
830entry:
831; CHECK: entry:
832; MAY-NEXT: Alive: <x y>
833; MUST-NEXT: Alive: <>
834  %x = alloca i8, align 4
835  %y = alloca i8, align 4
836
837  call void @llvm.lifetime.start.p0i8(i64 4, i8* %p)
838; CHECK: call void @llvm.lifetime.start.p0i8(i64 4, i8* %p)
839; MAY-NEXT: Alive: <x y>
840; MUST-NEXT: Alive: <>
841
842  call void @llvm.lifetime.start.p0i8(i64 4, i8* %x)
843; CHECK: call void @llvm.lifetime.start.p0i8(i64 4, i8* %x)
844; MAY-NEXT: Alive: <x y>
845; MUST-NEXT: Alive: <>
846
847  call void @llvm.lifetime.end.p0i8(i64 4, i8* %p)
848; CHECK: call void @llvm.lifetime.end.p0i8(i64 4, i8* %p)
849; MAY-NEXT: Alive: <x y>
850; MUST-NEXT: Alive: <>
851
852  ret void
853}
854
855define void @select_alloca(i1 %v) {
856; CHECK-LABEL: define void @select_alloca
857entry:
858; CHECK: entry:
859; MAY-NEXT: Alive: <x y>
860; MUST-NEXT: Alive: <>
861  %x = alloca i8, align 4
862  %y = alloca i8, align 4
863  %cxcy = select i1 %v, i8* %x, i8* %y
864
865  call void @llvm.lifetime.start.p0i8(i64 1, i8* %cxcy)
866; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %cxcy)
867; MAY-NEXT: Alive: <x y>
868; MUST-NEXT: Alive: <>
869
870  call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
871; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %x)
872; MAY-NEXT: Alive: <x y>
873; MUST-NEXT: Alive: <>
874
875  call void @llvm.lifetime.end.p0i8(i64 1, i8* %x)
876; CHECK: call void @llvm.lifetime.end.p0i8(i64 1, i8* %x)
877; MAY-NEXT: Alive: <x y>
878; MUST-NEXT: Alive: <>
879
880  ret void
881}
882
883define void @alloca_offset() {
884; CHECK-LABEL: define void @alloca_offset
885entry:
886; CHECK: entry:
887; MAY-NEXT: Alive: <x>
888; MUST-NEXT: Alive: <>
889  %x = alloca [5 x i32], align 4
890  %x2 = getelementptr [5 x i32], [5 x i32]* %x, i64 0, i64 1
891
892  call void @llvm.lifetime.start.p0i32(i64 20, i32* %x2)
893; CHECK: call void @llvm.lifetime.start.p0i32(i64 20, i32* %x2)
894; MAY-NEXT: Alive: <x>
895; MUST-NEXT: Alive: <>
896
897  call void @llvm.lifetime.end.p0i32(i64 20, i32* %x2)
898; CHECK: call void @llvm.lifetime.end.p0i32(i64 20, i32* %x2)
899; MAY-NEXT: Alive: <x>
900; MUST-NEXT: Alive: <>
901
902  ret void
903}
904
905define void @alloca_size() {
906; CHECK-LABEL: define void @alloca_size
907entry:
908; CHECK: entry:
909; MAY-NEXT: Alive: <x>
910; MUST-NEXT: Alive: <>
911  %x = alloca [5 x i32], align 4
912  %x2 = getelementptr [5 x i32], [5 x i32]* %x, i64 0, i64 0
913
914  call void @llvm.lifetime.start.p0i32(i64 15, i32* %x2)
915; CHECK: call void @llvm.lifetime.start.p0i32(i64 15, i32* %x2)
916; MAY-NEXT: Alive: <x>
917; MUST-NEXT: Alive: <>
918
919  call void @llvm.lifetime.end.p0i32(i64 15, i32* %x2)
920; CHECK: call void @llvm.lifetime.end.p0i32(i64 15, i32* %x2)
921; MAY-NEXT: Alive: <x>
922; MUST-NEXT: Alive: <>
923
924  ret void
925}
926
927declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
928declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
929declare void @llvm.lifetime.start.p0i32(i64, i32* nocapture)
930declare void @llvm.lifetime.end.p0i32(i64, i32* nocapture)
931declare void @capture8(i8*)
932declare void @capture32(i32*)
933declare void @capture64(i64*)
934declare void @capture100x32([100 x i32]*)
935