xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/loop-deletion/dead-loop.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; RUN: opt %s -passes=loop-deletion -S -o - \
2; RUN: | FileCheck %s
3; RUN: opt --try-experimental-debuginfo-iterators %s -passes=loop-deletion -S -o - \
4; RUN: | FileCheck %s
5
6;; $ cat test.cpp:
7;; void esc(int*);
8;; void fun() {
9;;   int Counter = 0;
10;;   for (; Counter < 2; Counter++) {}
11;;   esc(&Counter);
12;; }
13;;
14;; IR grabbed before loop-deletion in:
15;; $ clang++ -O2 -g -Xclang -fexperimental-assignment-tracking
16;;
17;; for.cond is a dead loop - the debug intrinsic inside will be moved to the
18;; exit block (and made undef) and then the loop will be deleted. Ensure that
19;; the dbg.assign intrinsic doesn't get transformed into a dbg.value by
20;; mistake.
21
22; CHECK: for.end:
23; CHECK-NEXT: #dbg_assign(i32 undef,{{.+}}, !DIExpression({{.+}}), ![[ID:[0-9]+]], ptr %Counter, !DIExpression(),
24; CHECK-NEXT: store i32 2, ptr %Counter, align 4,{{.*}}!DIAssignID ![[ID]]
25
26define dso_local void @_Z3funv() local_unnamed_addr #0 !dbg !7 {
27entry:
28  %Counter = alloca i32, align 4, !DIAssignID !13
29  call void @llvm.dbg.assign(metadata i1 undef, metadata !11, metadata !DIExpression(), metadata !13, metadata ptr %Counter, metadata !DIExpression()), !dbg !14
30  call void @llvm.dbg.assign(metadata i32 0, metadata !11, metadata !DIExpression(), metadata !16, metadata ptr %Counter, metadata !DIExpression()), !dbg !14
31  br label %for.cond, !dbg !17
32
33for.cond:                                         ; preds = %for.cond, %entry
34  call void @llvm.dbg.assign(metadata i32 undef, metadata !11, metadata !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value), metadata !16, metadata ptr %Counter, metadata !DIExpression()), !dbg !14
35  br i1 false, label %for.cond, label %for.end, !dbg !18, !llvm.loop !20
36
37for.end:                                          ; preds = %for.cond
38  store i32 2, ptr %Counter, align 4, !dbg !14, !DIAssignID !16
39  call void @_Z3escPi(ptr noundef nonnull %Counter), !dbg !27
40  ret void, !dbg !28
41}
42
43declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
44declare !dbg !29 dso_local void @_Z3escPi(ptr noundef) local_unnamed_addr
45declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
46declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
47
48!llvm.dbg.cu = !{!0}
49!llvm.module.flags = !{!2, !3, !4, !5, !1000}
50!llvm.ident = !{!6}
51
52!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
53!1 = !DIFile(filename: "test.cpp", directory: "/")
54!2 = !{i32 7, !"Dwarf Version", i32 5}
55!3 = !{i32 2, !"Debug Info Version", i32 3}
56!4 = !{i32 1, !"wchar_size", i32 4}
57!5 = !{i32 7, !"uwtable", i32 1}
58!6 = !{!"clang version 14.0.0)"}
59!7 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
60!8 = !DISubroutineType(types: !9)
61!9 = !{null}
62!10 = !{!11}
63!11 = !DILocalVariable(name: "Counter", scope: !7, file: !1, line: 3, type: !12)
64!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
65!13 = distinct !DIAssignID()
66!14 = !DILocation(line: 0, scope: !7)
67!15 = !DILocation(line: 3, column: 3, scope: !7)
68!16 = distinct !DIAssignID()
69!17 = !DILocation(line: 4, column: 3, scope: !7)
70!18 = !DILocation(line: 4, column: 3, scope: !19)
71!19 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 3)
72!20 = distinct !{!20, !18, !21, !22}
73!21 = !DILocation(line: 4, column: 35, scope: !19)
74!22 = !{!"llvm.loop.mustprogress"}
75!27 = !DILocation(line: 5, column: 3, scope: !7)
76!28 = !DILocation(line: 6, column: 1, scope: !7)
77!29 = !DISubprogram(name: "esc", linkageName: "_Z3escPi", scope: !1, file: !1, line: 1, type: !30, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !33)
78!30 = !DISubroutineType(types: !31)
79!31 = !{null, !32}
80!32 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
81!33 = !{}
82!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
83