1 # RUN: llc %s -o - -mtriple=x86_64-unknown-unknown \
2 # RUN: -experimental-debug-variable-locations \
3 # RUN: -run-pass=phi-node-elimination,livedebugvars,greedy,virtregrewriter \
6 # This test checks that for a very simple PHI, we produce a corresponding
7 # DBG_PHI instruction, that a DBG_INSTR_REF refers to. Tests the path through
8 # phi-node-elimination, live debug variables, and then placement after register
11 # Original code, compiled with only -mem2reg, then fed to llc -stop-before...
14 # int foo(int bar, int baz) {
26 ; ModuleID = 'promoted.ll'
27 source_filename = "test.c"
28 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
29 target triple = "x86_64-unknown-linux-gnu"
31 define dso_local i32 @foo(i32 %bar, i32 %baz) !dbg !7 {
33 call void @llvm.dbg.value(metadata i32 %bar, metadata !11, metadata !DIExpression()), !dbg !12
34 call void @llvm.dbg.value(metadata i32 %baz, metadata !13, metadata !DIExpression()), !dbg !12
35 call void @llvm.dbg.value(metadata i32 0, metadata !14, metadata !DIExpression()), !dbg !12
36 %call = call i32 @ext(i32 0), !dbg !15
37 %tobool = icmp ne i32 %call, 0, !dbg !15
38 br i1 %tobool, label %if.end, label %if.else, !dbg !17
40 if.else: ; preds = %entry
41 call void @llvm.dbg.value(metadata i32 %baz, metadata !14, metadata !DIExpression()), !dbg !12
44 if.end: ; preds = %entry, %if.else
45 %either.0 = phi i32 [ %baz, %if.else ], [ %bar, %entry ], !dbg !18
46 call void @llvm.dbg.value(metadata i32 %either.0, metadata !14, metadata !DIExpression()), !dbg !12
47 ret i32 %either.0, !dbg !19
50 declare dso_local i32 @ext(i32)
52 ; Function Attrs: nounwind readnone speculatable willreturn
53 declare void @llvm.dbg.value(metadata, metadata, metadata)
56 !llvm.module.flags = !{!3, !4, !5}
59 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
60 !1 = !DIFile(filename: "test.c", directory: ".")
62 !3 = !{i32 7, !"Dwarf Version", i32 4}
63 !4 = !{i32 2, !"Debug Info Version", i32 3}
64 !5 = !{i32 1, !"wchar_size", i32 4}
66 !7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
67 !8 = !DISubroutineType(types: !9)
69 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
70 !11 = !DILocalVariable(name: "bar", arg: 1, scope: !7, file: !1, line: 2, type: !10)
71 !12 = !DILocation(line: 0, scope: !7)
72 !13 = !DILocalVariable(name: "baz", arg: 2, scope: !7, file: !1, line: 2, type: !10)
73 !14 = !DILocalVariable(name: "either", scope: !7, file: !1, line: 3, type: !10)
74 !15 = !DILocation(line: 4, column: 7, scope: !16)
75 !16 = distinct !DILexicalBlock(scope: !7, file: !1, line: 4, column: 7)
76 !17 = !DILocation(line: 4, column: 7, scope: !7)
77 !18 = !DILocation(line: 0, scope: !16)
78 !19 = !DILocation(line: 9, column: 3, scope: !7)
84 tracksRegLiveness: true
87 - { id: 0, class: gr32 }
88 - { id: 1, class: gr32 }
89 - { id: 2, class: gr32 }
90 - { id: 3, class: gr32 }
91 - { id: 4, class: gr32 }
93 - { reg: '$edi', virtual-reg: '%1' }
94 - { reg: '$esi', virtual-reg: '%2' }
98 machineFunctionInfo: {}
101 successors: %bb.2(0x50000000), %bb.1(0x30000000)
104 DBG_VALUE $edi, $noreg, !11, !DIExpression(), debug-location !12
105 DBG_VALUE $esi, $noreg, !13, !DIExpression(), debug-location !12
106 %2:gr32 = COPY killed $esi
107 %1:gr32 = COPY killed $edi
108 DBG_VALUE 0, $noreg, !14, !DIExpression(), debug-location !12
109 ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
110 %3:gr32 = MOV32r0 implicit-def dead $eflags
111 $edi = COPY killed %3, debug-location !15
112 CALL64pcrel32 @ext, csr_64, implicit $rsp, implicit $ssp, implicit killed $edi, implicit-def $rsp, implicit-def $ssp, implicit-def $eax, debug-location !15
113 ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !15
114 %4:gr32 = COPY killed $eax, debug-location !15
115 TEST32rr killed %4, %4, implicit-def $eflags, debug-location !15
116 JCC_1 %bb.2, 5, implicit killed $eflags, debug-location !17
117 JMP_1 %bb.1, debug-location !17
121 ; CHECK-LABEL: bb.2.if.end:
123 %0:gr32 = PHI %1, %bb.0, %2, %bb.1, debug-instr-number 1, debug-location !18
124 DBG_INSTR_REF !14, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !12
\r
125 ; CHECK: DBG_PHI $ebp, 1
126 ; CHECK: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)
\r
127 $eax = COPY killed %0, debug-location !19
128 ; Confirm that %0 is allocated in $ebp,
129 ; CHECK: $eax = COPY killed renamable $ebp
130 RET 0, killed $eax, debug-location !19