1 ; RUN: opt %s -passes='cgscc(function(sroa,instcombine),inline),function(instcombine,sroa),verify' -S -o - | FileCheck %s
2 ; RUN: opt --try-experimental-debuginfo-iterators %s -passes='cgscc(function(sroa,instcombine),inline),function(instcombine,sroa),verify' -S -o - | FileCheck %s
4 ; This test checks that SROA pass processes debug info correctly if applied twice.
5 ; Specifically, after SROA works first time, instcombine converts dbg.declare
6 ; intrinsics into dbg.value. Inlining creates new opportunities for SROA,
7 ; so it is called again. This time it does not handle correctly previously
8 ; inserted dbg.value intrinsics: current SROA implementation while doing
9 ; "Migrate debug information from the old alloca to the new alloca(s)" handles
10 ; only dbg.declare intrinsic. In this case, original dbg.declare was lowered by
11 ; instcombine pass into dbg.value. When it comes into SROA second time, all dbg.value
12 ; intrinsics, inserted by instcombine pass before second SROA, just not updated
13 ; (though SROA was done). The fix is to not lower dbg.declare for structures.
16 ; Hand-reduced from this example (-g -O -mllvm -disable-llvm-optzns -gno-column-info):
21 ; bool IsNull ( ) { return p1 == 0; }
29 ; if (result.IsNull())
32 ; return result.p1 + 1;
36 ; CHECK: %[[RESULT:.*]] = call i32 @_Z3foov
37 ; CHECK: #dbg_value(i32 %[[RESULT]], [[METADATA_IDX1:![0-9]+]]
39 ; CHECK: DICompileUnit
40 ; CHECK: [[METADATA_IDX1]] = !DILocalVariable(name: "result"
42 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
43 target triple = "x86_64-unknown-linux-gnu"
45 %struct.S1 = type { i32 }
47 $_ZN2S16IsNullEv = comdat any
49 define dso_local i32 @_Z3barv() !dbg !7 {
51 %retval = alloca i32, align 4
52 %result = alloca %struct.S1, align 4
53 %cleanup.dest.slot = alloca i32, align 4
54 call void @llvm.lifetime.start.p0(i64 4, ptr %result) #5, !dbg !21
55 call void @llvm.dbg.declare(metadata ptr %result, metadata !12, metadata !DIExpression()), !dbg !21
56 %call = call i32 @_Z3foov(), !dbg !21
57 store i32 %call, ptr %result, align 4, !dbg !21
58 %call1 = call zeroext i1 @_ZN2S16IsNullEv(ptr %result), !dbg !22
59 br i1 %call1, label %if.then, label %if.end, !dbg !24
61 if.then: ; preds = %entry
62 store i32 0, ptr %retval, align 4, !dbg !25
63 store i32 1, ptr %cleanup.dest.slot, align 4
64 br label %cleanup, !dbg !25
66 if.end: ; preds = %entry
67 %0 = load i32, ptr %result, align 4, !dbg !26
68 %add = add nsw i32 %0, 1, !dbg !26
69 store i32 %add, ptr %retval, align 4, !dbg !26
70 store i32 1, ptr %cleanup.dest.slot, align 4
71 br label %cleanup, !dbg !26
73 cleanup: ; preds = %if.end, %if.then
74 call void @llvm.lifetime.end.p0(i64 4, ptr %result) #5, !dbg !32
75 %1 = load i32, ptr %retval, align 4, !dbg !32
79 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
81 declare void @llvm.dbg.declare(metadata, metadata, metadata)
83 declare dso_local i32 @_Z3foov()
85 define linkonce_odr dso_local zeroext i1 @_ZN2S16IsNullEv(ptr %this) #4 comdat align 2 !dbg !33 {
87 %this.addr = alloca ptr, align 8
88 store ptr %this, ptr %this.addr, align 8
89 call void @llvm.dbg.declare(metadata ptr %this.addr, metadata !35, metadata !DIExpression()), !dbg !39
90 %this1 = load ptr, ptr %this.addr, align 8
91 %0 = load i32, ptr %this1, align 4, !dbg !40
92 %cmp = icmp eq i32 %0, 0, !dbg !40
96 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
99 !llvm.module.flags = !{!3, !4, !5}
102 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
103 !1 = !DIFile(filename: "sroa-after-inlining.cpp", directory: "")
105 !3 = !{i32 2, !"Dwarf Version", i32 4}
106 !4 = !{i32 2, !"Debug Info Version", i32 3}
107 !5 = !{i32 1, !"wchar_size", i32 4}
109 !7 = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
110 !8 = !DISubroutineType(types: !9)
112 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
114 !12 = !DILocalVariable(name: "result", scope: !7, file: !1, line: 10, type: !13)
115 !13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S1", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !14, identifier: "_ZTS2S1")
117 !15 = !DIDerivedType(tag: DW_TAG_member, name: "p1", scope: !13, file: !1, line: 2, baseType: !10, size: 32)
118 !16 = !DISubprogram(name: "IsNull", linkageName: "_ZN2S16IsNullEv", scope: !13, file: !1, line: 4, type: !17, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
119 !17 = !DISubroutineType(types: !18)
121 !19 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
122 !20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
123 !21 = !DILocation(line: 10, scope: !7)
124 !22 = !DILocation(line: 12, scope: !23)
125 !23 = distinct !DILexicalBlock(scope: !7, file: !1, line: 12)
126 !24 = !DILocation(line: 12, scope: !7)
127 !25 = !DILocation(line: 13, scope: !23)
128 !26 = !DILocation(line: 15, scope: !7)
129 !32 = !DILocation(line: 16, scope: !7)
130 !33 = distinct !DISubprogram(name: "IsNull", linkageName: "_ZN2S16IsNullEv", scope: !13, file: !1, line: 4, type: !17, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !16, retainedNodes: !34)
132 !35 = !DILocalVariable(name: "this", arg: 1, scope: !33, type: !36, flags: DIFlagArtificial | DIFlagObjectPointer)
133 !36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
134 !39 = !DILocation(line: 0, scope: !33)
135 !40 = !DILocation(line: 4, scope: !33)