1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3declare void @llvm.dbg.declare(metadata, metadata, metadata)
4declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
5declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
6declare void @foo(i8* nocapture, i8* nocapture)
7
8define void @bar(i1 %flag) #0 !dbg !4 {
9entry:
10; CHECK-LABEL: @bar(
11; CHECK: %[[T:[^ ]+]] = getelementptr inbounds [1 x i8], [1 x i8]* %text
12; CHECK: %[[B:[^ ]+]] = getelementptr inbounds [1 x i8], [1 x i8]* %buff
13; CHECK: if:
14; CHECK-NEXT: br label %bb2
15; CHECK: bb2:
16; CHECK-NEXT: br label %bb3
17; CHECK: bb3:
18; CHECK-NEXT: call void @llvm.dbg.declare
19; CHECK-NEXT: br label %fin
20; CHECK: call void @llvm.lifetime.start.p0i8(i64 1, i8* %[[T]])
21; CHECK-NEXT: call void @llvm.lifetime.start.p0i8(i64 1, i8* %[[B]])
22; CHECK-NEXT: call void @foo(i8* %[[B]], i8* %[[T]])
23; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* %[[B]])
24; CHECK-NEXT: call void @llvm.lifetime.end.p0i8(i64 1, i8* %[[T]])
25  %text = alloca [1 x i8], align 1
26  %buff = alloca [1 x i8], align 1
27  %0 = getelementptr inbounds [1 x i8], [1 x i8]* %text, i64 0, i64 0
28  %1 = getelementptr inbounds [1 x i8], [1 x i8]* %buff, i64 0, i64 0
29  br i1 %flag, label %if, label %else
30
31if:
32  call void @llvm.lifetime.start.p0i8(i64 1, i8* %0)
33  call void @llvm.lifetime.start.p0i8(i64 1, i8* %1)
34  call void @llvm.lifetime.end.p0i8(i64 1, i8* %1)
35  call void @llvm.lifetime.end.p0i8(i64 1, i8* %0)
36  br label %bb2
37
38bb2:
39  call void @llvm.lifetime.start.p0i8(i64 1, i8* %0)
40  call void @llvm.lifetime.start.p0i8(i64 1, i8* %1)
41  call void @llvm.lifetime.end.p0i8(i64 1, i8* %0)
42  call void @llvm.lifetime.end.p0i8(i64 1, i8* %1)
43  br label %bb3
44
45bb3:
46  call void @llvm.lifetime.start.p0i8(i64 1, i8* %0)
47  call void @llvm.dbg.declare(metadata [1 x i8]* %text, metadata !14, metadata !25), !dbg !26
48  call void @llvm.lifetime.end.p0i8(i64 1, i8* %0)
49  br label %fin
50
51else:
52  call void @llvm.lifetime.start.p0i8(i64 1, i8* %0)
53  call void @llvm.lifetime.start.p0i8(i64 1, i8* %1)
54  call void @foo(i8* %1, i8* %0)
55  call void @llvm.lifetime.end.p0i8(i64 1, i8* %1)
56  call void @llvm.lifetime.end.p0i8(i64 1, i8* %0)
57  br  label %fin
58
59fin:
60  ret void
61}
62
63attributes #0 = { "null-pointer-is-valid"="true" }
64
65!llvm.dbg.cu = !{!0}
66!llvm.module.flags = !{!22, !23}
67!llvm.ident = !{!24}
68
69!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 248826) (llvm/trunk 248827)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
70!1 = !DIFile(filename: "test.cpp", directory: "/home/user")
71!2 = !{}
72!4 = distinct !DISubprogram(name: "bar", linkageName: "bar", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !8)
73!5 = !DISubroutineType(types: !6)
74!6 = !{null, !7}
75!7 = !DIBasicType(name: "bool", size: 8, align: 8, encoding: DW_ATE_boolean)
76!8 = !{!9, !11, !12, !14, !21}
77!9 = !DILocalVariable(name: "Size", arg: 1, scope: !4, file: !1, line: 2, type: !10)
78!10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
79!11 = !DILocalVariable(name: "flag", arg: 2, scope: !4, file: !1, line: 2, type: !7)
80!12 = !DILocalVariable(name: "i", scope: !13, file: !1, line: 3, type: !10)
81!13 = distinct !DILexicalBlock(scope: !4, file: !1, line: 3, column: 3)
82!14 = !DILocalVariable(name: "text", scope: !15, file: !1, line: 4, type: !17)
83!15 = distinct !DILexicalBlock(scope: !16, file: !1, line: 3, column: 30)
84!16 = distinct !DILexicalBlock(scope: !13, file: !1, line: 3, column: 3)
85!17 = !DICompositeType(tag: DW_TAG_array_type, baseType: !18, size: 8, align: 8, elements: !19)
86!18 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
87!19 = !{!20}
88!20 = !DISubrange(count: 1)
89!21 = !DILocalVariable(name: "buff", scope: !15, file: !1, line: 5, type: !17)
90!22 = !{i32 2, !"Dwarf Version", i32 4}
91!23 = !{i32 2, !"Debug Info Version", i32 3}
92!24 = !{!"clang version 3.8.0 (trunk 248826) (llvm/trunk 248827)"}
93!25 = !DIExpression()
94!26 = !DILocation(line: 4, column: 10, scope: !15)
95