1; RUN: llc -start-before=codegenprepare -stop-after=codegenprepare -mtriple=x86_64-unknown-unknown %s -o - | FileCheck %s 2; RUN: llc -start-before=codegenprepare -stop-after=codegenprepare -mtriple=x86_64-unknown-unknown %s -o - --try-experimental-debuginfo-iterators | FileCheck %s 3; 4; CGP duplicates address calculation into each basic block that contains loads 5; or stores, so that they can be folded into instruction memory operands for 6; example. dbg.value's should be redirected to identify such local address 7; computations, to give the best opportunity for variable locations to be 8; preserved. 9; This test has two dbg.values in it, one before and one after the relevant 10; memory instruction. Test that the one before does _not_ get updated (as that 11; would either make it use-before-def or shift when the variable appears), and 12; that the dbg.value after the memory instruction does get updated. 13 14define dso_local i8 @foo(ptr %p, i32 %cond) !dbg !7 { 15entry: 16; There should be no dbg.values in this block. 17; CHECK-LABEL: entry: 18; CHECK-NOT: #dbg_value 19 %arith = getelementptr i8, ptr %p, 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: #dbg_value(ptr %arith, ![[DIVAR:[0-9]+]], 29; CHECK-SAME: !DIExpression() 30; CHECK-NEXT: %[[GEPVAR:[0-9a-zA-Z]+]] = getelementptr i8, ptr %p, 31; CHECK-SAME: i64 3 32; CHECK-NEXT: %loaded = load i8, ptr %[[GEPVAR]] 33; CHECK-NEXT: #dbg_value(ptr %[[GEPVAR]], 34; CHECK-SAME: ![[DIVAR]], 35; CHECK-NEXT: #dbg_value(!DIArgList(ptr %[[GEPVAR]], 36; CHECK-SAME: ptr %[[GEPVAR]]), ![[DIVAR]], 37 call void @llvm.dbg.value(metadata ptr %arith, metadata !12, metadata !DIExpression()), !dbg !14 38 %loaded = load i8, ptr %arith 39 call void @llvm.dbg.value(metadata ptr %arith, metadata !12, metadata !DIExpression()), !dbg !14 40 call void @llvm.dbg.value(metadata !DIArgList(ptr %arith, ptr %arith), metadata !12, metadata !DIExpression()), !dbg !14 41 ret i8 %loaded 42 43ret: 44 ret i8 0 45} 46 47; CHECK: ![[DIVAR]] = !DILocalVariable(name: "p", 48 49declare void @llvm.dbg.value(metadata, metadata, metadata) 50 51!llvm.dbg.cu = !{!0} 52!llvm.module.flags = !{!3, !4, !5} 53!llvm.ident = !{!6} 54 55!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None) 56!1 = !DIFile(filename: "test.cpp", directory: ".") 57!2 = !{} 58!3 = !{i32 2, !"Dwarf Version", i32 4} 59!4 = !{i32 2, !"Debug Info Version", i32 3} 60!5 = !{i32 1, !"wchar_size", i32 4} 61!6 = !{!"clang version 8.0.0 (trunk 348209)"} 62!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) 63!8 = !DISubroutineType(types: !9) 64!9 = !{null, !10} 65!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 66!11 = !{!12} 67!12 = !DILocalVariable(name: "p", arg: 1, scope: !7, file: !1, line: 4, type: !10) 68!14 = !DILocation(line: 4, column: 15, scope: !7) 69!20 = distinct !DILexicalBlock(scope: !7, file: !1, line: 8, column: 7) 70