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