1 ; RUN: opt %s -sroa -instcombine -inline -instcombine -sroa -verify -S -o - | FileCheck %s
3 ; This test checks that SROA pass processes debug info correctly if applied twice.
4 ; Specifically, after SROA works first time, instcombine converts dbg.declare
5 ; intrinsics into dbg.value. Inlining creates new opportunities for SROA,
6 ; so it is called again. This time it does not handle correctly previously
7 ; inserted dbg.value intrinsics: current SROA implementation while doing
8 ; "Migrate debug information from the old alloca to the new alloca(s)" handles
9 ; only dbg.declare intrinsic. In this case, original dbg.declare was lowered by
10 ; instcombine pass into dbg.value. When it comes into SROA second time, all dbg.value
11 ; intrinsics, inserted by instcombine pass before second SROA, just not updated
12 ; (though SROA was done). The fix is to not lower dbg.declare for structures.
15 ; Hand-reduced from this example (-g -O -mllvm -disable-llvm-optzns -gno-column-info):
20 ; bool IsNull ( ) { return p1 == 0; }
28 ; if (result.IsNull())
31 ; return result.p1 + 1;
35 ; CHECK: %[[RESULT:.*]] = call i32 @_Z3foov
36 ; CHECK: llvm.dbg.value(metadata i32 %[[RESULT]], metadata [[METADATA_IDX1:![0-9]+]]
38 ; CHECK: DICompileUnit
39 ; CHECK: [[METADATA_IDX1]] = !DILocalVariable(name: "result"
41 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
42 target triple = "x86_64-unknown-linux-gnu"
44 %struct.S1 = type { i32 }
46 $_ZN2S16IsNullEv = comdat any
48 define dso_local i32 @_Z3barv() !dbg !7 {
50 %retval = alloca i32, align 4
51 %result = alloca %struct.S1, align 4
52 %cleanup.dest.slot = alloca i32, align 4
53 %0 = bitcast %struct.S1* %result to i8*, !dbg !21
54 call void @llvm.lifetime.start.p0i8(i64 4, i8* %0) #5, !dbg !21
55 call void @llvm.dbg.declare(metadata %struct.S1* %result, metadata !12, metadata !DIExpression()), !dbg !21
56 %call = call i32 @_Z3foov(), !dbg !21
57 %coerce.dive = getelementptr inbounds %struct.S1, %struct.S1* %result, i32 0, i32 0, !dbg !21
58 store i32 %call, i32* %coerce.dive, align 4, !dbg !21
59 %call1 = call zeroext i1 @_ZN2S16IsNullEv(%struct.S1* %result), !dbg !22
60 br i1 %call1, label %if.then, label %if.end, !dbg !24
62 if.then: ; preds = %entry
63 store i32 0, i32* %retval, align 4, !dbg !25
64 store i32 1, i32* %cleanup.dest.slot, align 4
65 br label %cleanup, !dbg !25
67 if.end: ; preds = %entry
68 %p1 = getelementptr inbounds %struct.S1, %struct.S1* %result, i32 0, i32 0, !dbg !26
69 %1 = load i32, i32* %p1, align 4, !dbg !26
70 %add = add nsw i32 %1, 1, !dbg !26
71 store i32 %add, i32* %retval, align 4, !dbg !26
72 store i32 1, i32* %cleanup.dest.slot, align 4
73 br label %cleanup, !dbg !26
75 cleanup: ; preds = %if.end, %if.then
76 %2 = bitcast %struct.S1* %result to i8*, !dbg !32
77 call void @llvm.lifetime.end.p0i8(i64 4, i8* %2) #5, !dbg !32
78 %3 = load i32, i32* %retval, align 4, !dbg !32
82 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
84 declare void @llvm.dbg.declare(metadata, metadata, metadata)
86 declare dso_local i32 @_Z3foov()
88 define linkonce_odr dso_local zeroext i1 @_ZN2S16IsNullEv(%struct.S1* %this) #4 comdat align 2 !dbg !33 {
90 %this.addr = alloca %struct.S1*, align 8
91 store %struct.S1* %this, %struct.S1** %this.addr, align 8
92 call void @llvm.dbg.declare(metadata %struct.S1** %this.addr, metadata !35, metadata !DIExpression()), !dbg !39
93 %this1 = load %struct.S1*, %struct.S1** %this.addr, align 8
94 %p1 = getelementptr inbounds %struct.S1, %struct.S1* %this1, i32 0, i32 0, !dbg !40
95 %0 = load i32, i32* %p1, align 4, !dbg !40
96 %cmp = icmp eq i32 %0, 0, !dbg !40
100 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
103 !llvm.module.flags = !{!3, !4, !5}
106 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
107 !1 = !DIFile(filename: "sroa-after-inlining.cpp", directory: "")
109 !3 = !{i32 2, !"Dwarf Version", i32 4}
110 !4 = !{i32 2, !"Debug Info Version", i32 3}
111 !5 = !{i32 1, !"wchar_size", i32 4}
113 !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)
114 !8 = !DISubroutineType(types: !9)
116 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
118 !12 = !DILocalVariable(name: "result", scope: !7, file: !1, line: 10, type: !13)
119 !13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S1", file: !1, line: 1, size: 32, flags: DIFlagTypePassByValue, elements: !14, identifier: "_ZTS2S1")
121 !15 = !DIDerivedType(tag: DW_TAG_member, name: "p1", scope: !13, file: !1, line: 2, baseType: !10, size: 32)
122 !16 = !DISubprogram(name: "IsNull", linkageName: "_ZN2S16IsNullEv", scope: !13, file: !1, line: 4, type: !17, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
123 !17 = !DISubroutineType(types: !18)
125 !19 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
126 !20 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
127 !21 = !DILocation(line: 10, scope: !7)
128 !22 = !DILocation(line: 12, scope: !23)
129 !23 = distinct !DILexicalBlock(scope: !7, file: !1, line: 12)
130 !24 = !DILocation(line: 12, scope: !7)
131 !25 = !DILocation(line: 13, scope: !23)
132 !26 = !DILocation(line: 15, scope: !7)
133 !32 = !DILocation(line: 16, scope: !7)
134 !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)
136 !35 = !DILocalVariable(name: "this", arg: 1, scope: !33, type: !36, flags: DIFlagArtificial | DIFlagObjectPointer)
137 !36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
138 !39 = !DILocation(line: 0, scope: !33)
139 !40 = !DILocation(line: 4, scope: !33)