xref: /llvm-project/llvm/test/Transforms/LoopUnroll/runtime-epilog-debuginfo.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt -passes=loop-unroll -unroll-runtime -unroll-runtime-epilog -S %s | FileCheck %s
2; RUN: opt -passes=loop-unroll -unroll-runtime -unroll-runtime-epilog -S %s --try-experimental-debuginfo-iterators | FileCheck %s
3
4; Test that epilogue is tagged with the same debug information as original loop body rather than original loop exit.
5
6; CHECK: for.body.i:
7; CHECK:   br i1 {{.*}}, label %lee1.exit.loopexit.unr-lcssa.loopexit, label %for.body.i, !dbg ![[LOOP_LOC:[0-9]+]]
8; CHECK: lee1.exit.loopexit.unr-lcssa.loopexit:
9; CHECK:   br label %lee1.exit.loopexit.unr-lcssa, !dbg ![[LOOP_LOC]]
10; CHECK: lee1.exit.loopexit.unr-lcssa:
11; CHECK:   %lcmp.mod = icmp ne i32 %xtraiter, 0, !dbg ![[LOOP_LOC]]
12; CHECK:   br i1 %lcmp.mod, label %for.body.i.epil.preheader, label %lee1.exit.loopexit, !dbg ![[LOOP_LOC]]
13; CHECK: for.body.i.epil.preheader:
14; CHECK:   br label %for.body.i.epil, !dbg ![[LOOP_LOC]]
15; CHECK: for.body.i.epil:
16;; Ensure that when we clone the div/add/add and its following dbg.values,
17;; those dbg.values are remapped to the duplicated adds, not the originals.
18; CHECK:      %div.i.epil = sdiv i32 %t.08.i.epil, 2,
19; CHECK-NEXT: %add.i.epil = add i32 %t.08.i.epil, %a,
20; CHECK-NEXT: %add1.i.epil = add i32 %add.i.epil, %div.i.epil,
21; CHECK-NEXT: #dbg_value(i32 %add1.i.epil,
22; CHECK-NEXT: %inc.i.epil = add nuw i32 %i.09.i.epil, 1, !dbg !36
23; CHECK-NEXT: #dbg_value(i32 %inc.i.epil,
24; CHECK-NEXT: #dbg_value(i32 %inc.i.epil,
25; CHECK-NEXT: #dbg_value(i32 %add1.i.epil,
26
27; CHECK: lee1.exit.loopexit:
28; CHECK:   br label %lee1.exit, !dbg ![[EXIT_LOC:[0-9]+]]
29
30; CHECK-DAG: ![[LOOP_LOC]] = !DILocation(line: 5, column: 3, scope: !{{.*}}, inlinedAt: !{{.*}})
31; CHECK-DAG: ![[EXIT_LOC]] = !DILocation(line: 11, column: 12, scope: !{{.*}}, inlinedAt: !{{.*}})
32
33; Function Attrs: nounwind readnone
34define i32 @goo(i32 %a, i32 %b) local_unnamed_addr #0 !dbg !8 {
35entry:
36  tail call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata !13, metadata !15), !dbg !16
37  tail call void @llvm.dbg.value(metadata i32 %b, i64 0, metadata !14, metadata !15), !dbg !17
38  tail call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata !18, metadata !15), !dbg !26
39  tail call void @llvm.dbg.value(metadata i32 %b, i64 0, metadata !21, metadata !15), !dbg !28
40  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !22, metadata !15), !dbg !29
41  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !23, metadata !15), !dbg !30
42  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !23, metadata !15), !dbg !30
43  tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !22, metadata !15), !dbg !29
44  %cmp7.i = icmp eq i32 %b, 0, !dbg !31
45  br i1 %cmp7.i, label %lee1.exit, label %for.body.i.preheader, !dbg !33
46
47for.body.i.preheader:                             ; preds = %entry
48  br label %for.body.i, !dbg !34
49
50for.body.i:                                       ; preds = %for.body.i.preheader, %for.body.i
51  %i.09.i = phi i32 [ %inc.i, %for.body.i ], [ 0, %for.body.i.preheader ]
52  %t.08.i = phi i32 [ %add1.i, %for.body.i ], [ 0, %for.body.i.preheader ]
53  %div.i = sdiv i32 %t.08.i, 2, !dbg !34
54  %add.i = add i32 %t.08.i, %a, !dbg !35
55  %add1.i = add i32 %add.i, %div.i, !dbg !36
56  tail call void @llvm.dbg.value(metadata i32 %add1.i, i64 0, metadata !22, metadata !15), !dbg !29
57  %inc.i = add nuw i32 %i.09.i, 1, !dbg !37
58  tail call void @llvm.dbg.value(metadata i32 %inc.i, i64 0, metadata !23, metadata !15), !dbg !30
59  tail call void @llvm.dbg.value(metadata i32 %inc.i, i64 0, metadata !23, metadata !15), !dbg !30
60  tail call void @llvm.dbg.value(metadata i32 %add1.i, i64 0, metadata !22, metadata !15), !dbg !29
61  %exitcond.i = icmp eq i32 %inc.i, %b, !dbg !31
62  br i1 %exitcond.i, label %lee1.exit.loopexit, label %for.body.i, !dbg !33, !llvm.loop !38
63
64lee1.exit.loopexit:                               ; preds = %for.body.i
65  %add1.i.lcssa = phi i32 [ %add1.i, %for.body.i ]
66  br label %lee1.exit, !dbg !41
67
68lee1.exit:                                        ; preds = %lee1.exit.loopexit, %entry
69  %t.0.lcssa.i = phi i32 [ 0, %entry ], [ %add1.i.lcssa, %lee1.exit.loopexit ]
70  tail call void @llvm.dbg.value(metadata i32 %a, i64 0, metadata !44, metadata !15), !dbg !47
71  tail call void @llvm.dbg.value(metadata i32 %b, i64 0, metadata !45, metadata !15), !dbg !48
72  %add.i4 = add nsw i32 %b, %a, !dbg !41
73  %sub.i = sub nsw i32 %a, %b, !dbg !49
74  %mul.i = mul nsw i32 %add.i4, %sub.i, !dbg !50
75  %add = add nsw i32 %t.0.lcssa.i, %mul.i, !dbg !51
76  ret i32 %add, !dbg !52
77}
78
79; Function Attrs: nounwind readnone
80declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
81
82attributes #0 = { nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="arm7tdmi" "target-features"="+neon,+strict-align,+vfp3,-crypto,-fp-armv8,-fp16,-vfp4" "unsafe-fp-math"="false" "use-soft-float"="false" }
83attributes #1 = { nounwind readnone }
84
85!llvm.dbg.cu = !{!0}
86!llvm.module.flags = !{!3, !4, !5, !6}
87!llvm.ident = !{!7}
88
89!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Snapdragon LLVM ARM Compiler 4.0.5 (based on llvm.org 4.0+)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
90!1 = !DIFile(filename: "t.c", directory: "/prj/llvm-arm/scratch1/zhaoshiz/bugs/debug-symbol")
91!2 = !{}
92!3 = !{i32 2, !"Dwarf Version", i32 4}
93!4 = !{i32 2, !"Debug Info Version", i32 3}
94!5 = !{i32 1, !"wchar_size", i32 4}
95!6 = !{i32 1, !"min_enum_size", i32 4}
96!7 = !{!"Snapdragon LLVM ARM Compiler 4.0.5 (based on llvm.org 4.0+)"}
97!8 = distinct !DISubprogram(name: "goo", scope: !1, file: !1, line: 23, type: !9, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
98!9 = !DISubroutineType(types: !10)
99!10 = !{!11, !11, !11}
100!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
101!12 = !{!13, !14}
102!13 = !DILocalVariable(name: "a", arg: 1, scope: !8, file: !1, line: 23, type: !11)
103!14 = !DILocalVariable(name: "b", arg: 2, scope: !8, file: !1, line: 23, type: !11)
104!15 = !DIExpression()
105!16 = !DILocation(line: 23, column: 14, scope: !8)
106!17 = !DILocation(line: 23, column: 21, scope: !8)
107!18 = !DILocalVariable(name: "a", arg: 1, scope: !19, file: !1, line: 3, type: !11)
108!19 = distinct !DISubprogram(name: "lee1", scope: !1, file: !1, line: 3, type: !9, isLocal: true, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !20)
109!20 = !{!18, !21, !22, !23}
110!21 = !DILocalVariable(name: "b", arg: 2, scope: !19, file: !1, line: 3, type: !11)
111!22 = !DILocalVariable(name: "t", scope: !19, file: !1, line: 4, type: !11)
112!23 = !DILocalVariable(name: "i", scope: !24, file: !1, line: 5, type: !25)
113!24 = distinct !DILexicalBlock(scope: !19, file: !1, line: 5, column: 3)
114!25 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
115!26 = !DILocation(line: 3, column: 22, scope: !19, inlinedAt: !27)
116!27 = distinct !DILocation(line: 24, column: 27, scope: !8)
117!28 = !DILocation(line: 3, column: 29, scope: !19, inlinedAt: !27)
118!29 = !DILocation(line: 4, column: 7, scope: !19, inlinedAt: !27)
119!30 = !DILocation(line: 5, column: 17, scope: !24, inlinedAt: !27)
120!31 = !DILocation(line: 5, column: 23, scope: !32, inlinedAt: !27)
121!32 = distinct !DILexicalBlock(scope: !24, file: !1, line: 5, column: 3)
122!33 = !DILocation(line: 5, column: 3, scope: !24, inlinedAt: !27)
123!34 = !DILocation(line: 6, column: 13, scope: !32, inlinedAt: !27)
124!35 = !DILocation(line: 6, column: 11, scope: !32, inlinedAt: !27)
125!36 = !DILocation(line: 6, column: 7, scope: !32, inlinedAt: !27)
126!37 = !DILocation(line: 5, column: 28, scope: !32, inlinedAt: !27)
127!38 = distinct !{!38, !39, !40}
128!39 = !DILocation(line: 5, column: 3, scope: !24, inlinedAt: !27)
129!40 = !DILocation(line: 6, column: 14, scope: !24, inlinedAt: !27)
130!41 = !DILocation(line: 11, column: 12, scope: !42, inlinedAt: !46)
131!42 = distinct !DISubprogram(name: "lee2", scope: !1, file: !1, line: 10, type: !9, isLocal: true, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !43)
132!43 = !{!44, !45}
133!44 = !DILocalVariable(name: "a", arg: 1, scope: !42, file: !1, line: 10, type: !11)
134!45 = !DILocalVariable(name: "b", arg: 2, scope: !42, file: !1, line: 10, type: !11)
135!46 = distinct !DILocation(line: 24, column: 40, scope: !8)
136!47 = !DILocation(line: 10, column: 22, scope: !42, inlinedAt: !46)
137!48 = !DILocation(line: 10, column: 29, scope: !42, inlinedAt: !46)
138!49 = !DILocation(line: 11, column: 20, scope: !42, inlinedAt: !46)
139!50 = !DILocation(line: 11, column: 16, scope: !42, inlinedAt: !46)
140!51 = !DILocation(line: 24, column: 38, scope: !8)
141!52 = !DILocation(line: 24, column: 3, scope: !8)
142