xref: /llvm-project/llvm/test/DebugInfo/Generic/assignment-tracking/codegenprepare/sunk-addr.ll (revision 094572701dce4aaf36f4521d6cf750420d39f206)
1; REQUIRES: x86-registered-target
2; RUN: llc -start-before=codegenprepare -stop-after=codegenprepare \
3; RUN:   -mtriple=x86_64-unknown-unknown %s -o - \
4; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg."
5
6;; Test with RemoveDIs non-intrinsic debug-info too.
7; RUN: llc -start-before=codegenprepare -stop-after=codegenprepare \
8; RUN:   -mtriple=x86_64-unknown-unknown %s -o - --try-experimental-debuginfo-iterators \
9; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg."
10
11;; Check that when CodeGenPrepare moves an address computation to a block it's
12;; used in its dbg.assign uses are updated.
13;;
14;; Based on llvm/test/DebugInfo/X86/codegenprepare-addrsink.ll
15
16define dso_local i8 @foo(ptr %p, i32 %cond) !dbg !7 {
17entry:
18  %casted = bitcast ptr %p to ptr
19  %arith = getelementptr i8, ptr %casted, i32 3
20  %load1 = load i8, ptr %arith
21  %cmpresult = icmp eq i32 %cond, 0
22  br i1 %cmpresult, label %next, label %ret
23
24next:
25; Address calcs should be duplicated into this block. One dbg.value should be
26; updated, and the other should not.
27; CHECK-LABEL: next:
28; CHECK:       %[[CASTVAR:[0-9a-zA-Z]+]] = bitcast ptr %p to ptr
29; CHECK-NEXT:  #dbg_assign(ptr %arith, ![[DIVAR:[0-9]+]],
30; CHECK-NEXT:  %[[GEPVAR:[0-9a-zA-Z]+]] = getelementptr i8, ptr %[[CASTVAR]], i64 3
31; CHECK-NEXT:  %loaded = load i8, ptr %[[GEPVAR]]
32; CHECK-NEXT:  #dbg_assign(ptr %[[GEPVAR]], ![[DIVAR]],
33  call void @llvm.dbg.assign(metadata ptr %arith, metadata !12, metadata !DIExpression(), metadata !21, metadata ptr undef, metadata !DIExpression()), !dbg !14
34  %loaded = load i8, ptr %arith
35  call void @llvm.dbg.assign(metadata ptr %arith, metadata !12, metadata !DIExpression(), metadata !21, metadata ptr undef, metadata !DIExpression()), !dbg !14
36  ret i8 %loaded
37
38ret:
39  ret i8 0
40}
41
42; CHECK: ![[DIVAR]] = !DILocalVariable(name: "p",
43
44declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
45
46!llvm.dbg.cu = !{!0}
47!llvm.module.flags = !{!3, !4, !5, !1000}
48!llvm.ident = !{!6}
49
50!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
51!1 = !DIFile(filename: "test.cpp", directory: ".")
52!2 = !{}
53!3 = !{i32 2, !"Dwarf Version", i32 4}
54!4 = !{i32 2, !"Debug Info Version", i32 3}
55!5 = !{i32 1, !"wchar_size", i32 4}
56!6 = !{!"clang version 8.0.0 (trunk 348209)"}
57!7 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 4, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
58!8 = !DISubroutineType(types: !9)
59!9 = !{null, !10}
60!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
61!11 = !{!12}
62!12 = !DILocalVariable(name: "p", arg: 1, scope: !7, file: !1, line: 4, type: !10)
63!14 = !DILocation(line: 4, column: 15, scope: !7)
64!20 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7)
65!21 = distinct !DIAssignID()
66!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
67