300 lines · plain
1; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel -experimental-debug-variable-locations=false \2; RUN: | FileCheck %s --check-prefix=NORMAL \3; RUN: --implicit-check-not=debug-instr-number \4; RUN: --implicit-check-not=DBG_INSTR_REF5; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \6; RUN: -experimental-debug-variable-locations -verify-machineinstrs \7; RUN: | FileCheck %s --check-prefix=INSTRREF \8; RUN: --implicit-check-not=DBG_VALUE9; RUN: llc %s -mtriple=x86_64-unknown-unknown -o - -stop-before=finalize-isel \10; RUN: -experimental-debug-variable-locations -verify-machineinstrs \11; RUN: -fast-isel \12; RUN: | FileCheck %s --check-prefix=FASTISEL-INSTRREF \13; RUN: --implicit-check-not=DBG_VALUE14 15; NORMAL: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks",16; NORMAL: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees",17; INSTRREF: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks",18; INSTRREF: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees",19; FASTISEL-INSTRREF: ![[SOCKS:[0-9]+]] = !DILocalVariable(name: "socks",20; FASTISEL-INSTRREF: ![[KNEES:[0-9]+]] = !DILocalVariable(name: "knees",21 22; Test that SelectionDAG produces DBG_VALUEs normally, but DBG_INSTR_REFs when23; asked.24 25; NORMAL-LABEL: name: foo26 27; NORMAL: %[[REG0:[0-9]+]]:gr32 = ADD32rr28; NORMAL-NEXT: DBG_VALUE %[[REG0]]29; NORMAL-NEXT: DBG_VALUE_LIST {{.+}}, %[[REG0]], 230; NORMAL-NEXT: %[[REG1:[0-9]+]]:gr32 = ADD32rr31; NORMAL-NEXT: DBG_VALUE %[[REG1]]32; NORMAL-NEXT: DBG_VALUE_LIST {{.+}}, %[[REG1]], %[[REG0]]33 34; Note that I'm baking in an assumption of one-based ordering here. We could35; capture and check for the instruction numbers, we'd rely on machine verifier36; ensuring there were no duplicates.37 38; INSTRREF-LABEL: name: foo39 40; INSTRREF: ADD32rr41; INSTRREF-SAME: debug-instr-number 142; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)43; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0), 244; INSTRREF-NEXT: ADD32rr45; INSTRREF-SAME: debug-instr-number 246; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)47; INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0), dbg-instr-ref(1, 0)48 49; Test that fast-isel will produce DBG_INSTR_REFs too, except for debug values50; using DIArgList, which is not supported in FastIsel.51 52; FASTISEL-INSTRREF-LABEL: name: foo53 54; FASTISEL-INSTRREF: ADD32rr55; FASTISEL-INSTRREF-SAME: debug-instr-number 156; FASTISEL-INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)57; FASTISEL-INSTRREF-NEXT: DBG_VALUE $noreg, {{.+}}58; FASTISEL-INSTRREF-NEXT: ADD32rr59; FASTISEL-INSTRREF-SAME: debug-instr-number 260; FASTISEL-INSTRREF-NEXT: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)61; FASTISEL-INSTRREF-NEXT: DBG_VALUE $noreg, {{.+}}62 63@glob32 = global i32 064@glob16 = global i16 065@glob8 = global i8 066 67declare void @llvm.dbg.value(metadata, metadata, metadata)68declare void @llvm.dbg.declare(metadata, metadata, metadata)69 70define i32 @foo(i32 %bar, i32 %baz, i32 %qux) !dbg !7 {71entry:72 %0 = add i32 %bar, %baz, !dbg !1473 call void @llvm.dbg.value(metadata i32 %0, metadata !13, metadata !DIExpression()), !dbg !1474 call void @llvm.dbg.value(metadata !DIArgList(i32 %0, i32 2), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !1475 %1 = add i32 %0, %qux76 call void @llvm.dbg.value(metadata i32 %1, metadata !13, metadata !DIExpression()), !dbg !1477 call void @llvm.dbg.value(metadata !DIArgList(i32 %1, i32 %0), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus, DW_OP_stack_value)), !dbg !1478 ret i32 %1, !dbg !1479}80 81; In the code below, isel produces a large number of copies between subregisters82; to represent the gradually decreasing width of the argument. This gets83; optimized away into three stores, but it's an objective of the instruction84; referencing design that COPYs are not numbered: they move values, not define85; them. Test that nothing is numbered, and instead that appropriate86; substitutions with subregister details are recorded.87 88; NORMAL-LABEL: name: bar89 90; NORMAL: DBG_VALUE $rdi91; NORMAL-NEXT: %0:gr64_with_sub_8bit = COPY $rdi92; NORMAL-NEXT: DBG_VALUE %0,93; NORMAL-NEXT: %1:gr32 = COPY %0.sub_32bit,94; NORMAL-NEXT: DBG_VALUE %195; NORMAL: %3:gr16 = COPY %0.sub_16bit,96; NORMAL-NEXT: DBG_VALUE %397; NORMAL: %5:gr8 = COPY %0.sub_8bit,98; NORMAL-NEXT: DBG_VALUE %599 100; INSTRREF-LABEL: name: bar101 102;; 103; INSTRREF: debugValueSubstitutions:104; INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 0, subreg: 6 }105; INSTRREF-NEXT: - { srcinst: 4, srcop: 0, dstinst: 3, dstop: 0, subreg: 4 }106; INSTRREF-NEXT: - { srcinst: 6, srcop: 0, dstinst: 5, dstop: 0, subreg: 1 }107 108;; As a slight inefficiency today, multiple DBG_PHIs are created.109 110; INSTRREF: DBG_PHI $rdi, 5111; INSTRREF-NEXT: DBG_PHI $rdi, 3112; INSTRREF-NEXT: DBG_PHI $rdi, 1113;; Allow arguments to be specified by physreg DBG_VALUEs.114; INSTRREF-NEXT: DBG_VALUE $rdi115 116;; Don't test the location of these instr-refs, only that the three non-argument117;; dbg.values become DBG_INSTR_REFs. We previously checked that these numbers118;; get substituted, with appropriate subregister qualifiers.119; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)120; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(4, 0)121; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(6, 0)122 123;; In fast-isel, we get four DBG_INSTR_REFs (compared to three and one124;; DBG_VALUE with normal isel). We get additional substitutions as a result:125 126; FASTISEL-INSTRREF: debugValueSubstitutions:127; FASTISEL-INSTRREF-NEXT: - { srcinst: 3, srcop: 0, dstinst: 2, dstop: 0, subreg: 6 }128; FASTISEL-INSTRREF-NEXT: - { srcinst: 5, srcop: 0, dstinst: 4, dstop: 0, subreg: 6 }129; FASTISEL-INSTRREF-NEXT: - { srcinst: 6, srcop: 0, dstinst: 5, dstop: 0, subreg: 4 }130; FASTISEL-INSTRREF-NEXT - { srcinst: 8, srcop: 0, dstinst: 7, dstop: 0, subreg: 6 }131; FASTISEL-INSTRREF-NEXT - { srcinst: 9, srcop: 0, dstinst: 8, dstop: 0, subreg: 4 }132; FASTISEL-INSTRREF-NEXT - { srcinst: 10, srcop: 0, dstinst: 9, dstop: 0, subreg: 1 }133 134;; Those substitutions are anchored against these DBG_PHIs:135 136; FASTISEL-INSTRREF: DBG_PHI $rdi, 7137; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 4138; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 2139; FASTISEL-INSTRREF-NEXT: DBG_PHI $rdi, 1140 141; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(1, 0)142; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(3, 0)143; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(6, 0)144; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(10, 0)145 146define i32 @bar(i64 %bar) !dbg !20 {147entry:148 call void @llvm.dbg.value(metadata i64 %bar, metadata !21, metadata !DIExpression()), !dbg !22149 %0 = trunc i64 %bar to i32, !dbg !22150 call void @llvm.dbg.value(metadata i32 %0, metadata !21, metadata !DIExpression()), !dbg !22151 store i32 %0, ptr @glob32, !dbg !22152 %1 = trunc i32 %0 to i16, !dbg !22153 call void @llvm.dbg.value(metadata i16 %1, metadata !21, metadata !DIExpression()), !dbg !22154 store i16 %1, ptr @glob16, !dbg !22155 %2 = trunc i16 %1 to i8, !dbg !22156 call void @llvm.dbg.value(metadata i8 %2, metadata !21, metadata !DIExpression()), !dbg !22157 store i8 %2, ptr @glob8, !dbg !22158 ret i32 0, !dbg !22159}160 161; Ensure that we can track copies back to physreg defs, and throw in a subreg162; substitution for fun. The call to @xyzzy defines $rax, which gets copied to163; a VReg, and then truncated by a subreg copy. We should be able to track164; through the copies and walk back to the physreg def, labelling the CALL165; instruction. We should also be able to do this even when the block layout is166; crazily ordered.167 168; NORMAL-LABEL: name: baz169 170; NORMAL: CALL64pcrel32 target-flags(x86-plt) @xyzzy171; NORMAL: %2:gr64 = COPY $rax,172; NORMAL: %0:gr64 = COPY %2,173; NORMAL-LABEL: bb.1.slippers:174; NORMAL: DBG_VALUE %1175; NORMAL-LABEL: bb.2.shoes:176; NORMAL: %1:gr16 = COPY %0.sub_16bit177 178; INSTRREF-LABEL: name: baz179 180; INSTRREF: debugValueSubstitutions:181; INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 6, subreg: 4 }182 183; INSTRREF: CALL64pcrel32 target-flags(x86-plt) @xyzzy, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit-def $rax, debug-instr-number 1184; INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)185 186;; Fast-isel produces the same arrangement, a DBG_INSTR_REF pointing back to187;; the call instruction. However: the operand numbers are different (6 for188;; normal isel, 4 for fast-isel). This isn't because of debug-info differences,189;; it's because normal isel implicit-defs the stack registers, and fast-isel190;; does not. The meaning is the same.191 192; FASTISEL-INSTRREF-LABEL: name: baz193 194; FASTISEL-INSTRREF: debugValueSubstitutions:195; FASTISEL-INSTRREF-NEXT: - { srcinst: 2, srcop: 0, dstinst: 1, dstop: 4, subreg: 4 }196 197; FASTISEL-INSTRREF: CALL64pcrel32 target-flags(x86-plt) @xyzzy, csr_64, implicit $rsp, implicit $ssp, implicit-def $rax, debug-instr-number 1198; FASTISEL-INSTRREF: DBG_INSTR_REF {{.+}}, dbg-instr-ref(2, 0)199 200declare i64 @xyzzy()201 202define i32 @baz() !dbg !30 {203entry:204 %foo = call i64 @xyzzy(), !dbg !32205 br label %shoes206 207slippers:208 call void @llvm.dbg.value(metadata i16 %moo, metadata !31, metadata !DIExpression()), !dbg !32209 store i16 %moo, ptr @glob16, !dbg !32210 ret i32 0, !dbg !32211 212shoes:213 %moo = trunc i64 %foo to i16214 br label %slippers215}216 217;; Test for dbg.declare of non-stack-slot Values. These turn up with NRVO and 218;; other ABI scenarios where something is technically in memory, but we don't219;; refer to it relative to the stack pointer. We refer to these either with an220;; indirect DBG_VALUE, or a DBG_INSTR_REF with DW_OP_deref prepended.221;;222;; Test an inlined dbg.declare in a different scope + block, to test behaviours223;; where the debug intrinsic isn't in the first block. The normal-mode DBG_VALUE224;; is hoisted into the entry block for that. This is fine because the variable225;; location is never re-assigned. (FIXME: do we scope-trim / fail-to-propagate226;; these hoisted locations later?).227 228; NORMAL-LABEL: name: qux229;230; NORMAL: DBG_VALUE $rdi, 0, ![[SOCKS]], !DIExpression(),231; NORMAL-NEXT: %0:gr64 = COPY $rdi232; NORMAL-NEXT: DBG_VALUE %0, 0, ![[SOCKS]], !DIExpression(),233; NORMAL-NEXT: DBG_VALUE %0, 0, ![[KNEES]], !DIExpression(),234 235;; In instruction referencing mode, the "real" argument becomes a DBG_VALUE,236;; but the hoisted variable location from the inlined scope is a DBG_INSTR_REF.237 238; INSTRREF-LABEL: name: qux239 240; INSTRREF: DBG_PHI $rdi, 1241; INSTRREF-NEXT: DBG_VALUE $rdi, 0, ![[SOCKS]], !DIExpression(),242; INSTRREF-NEXT: %0:gr64 = COPY $rdi243; INSTRREF-NEXT: DBG_INSTR_REF ![[KNEES]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0),244 245; In fast-isel mode, neither variable are hoisted or forwarded to a physreg.246 247; FASTISEL-INSTRREF-LABEL: name: qux248 249; FASTISEL-INSTRREF: DBG_PHI $rdi, 1250; FASTISEL-INSTRREF: DBG_INSTR_REF ![[SOCKS]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0),251 252; FASTISEL-INSTRREF-LABEL: bb.1.lala:253; FASTISEL-INSTRREF: DBG_INSTR_REF ![[KNEES]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_deref), dbg-instr-ref(1, 0),254declare i64 @cheddar(ptr %arg)255 256define void @qux(ptr noalias sret(i32) %agg.result) !dbg !40 {257entry:258 call void @llvm.dbg.declare(metadata ptr %agg.result, metadata !41, metadata !DIExpression()), !dbg !42259 %foo = call i64 @cheddar(ptr %agg.result), !dbg !42260 br label %lala261 262lala:263 call void @llvm.dbg.declare(metadata ptr %agg.result, metadata !45, metadata !DIExpression()), !dbg !44264 ret void, !dbg !44265}266 267 268 269!llvm.dbg.cu = !{!0}270!llvm.module.flags = !{!3, !4}271 272!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)273!1 = !DIFile(filename: "exprconflict.c", directory: "/home/jmorse")274!2 = !{}275!3 = !{i32 2, !"Dwarf Version", i32 4}276!4 = !{i32 2, !"Debug Info Version", i32 3}277!7 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)278!8 = !DISubroutineType(types: !9)279!9 = !{!10, !10}280!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)281!11 = !{!13}282!13 = !DILocalVariable(name: "baz", scope: !7, file: !1, line: 6, type: !10)283!14 = !DILocation(line: 1, scope: !7)284!20 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !23)285!21 = !DILocalVariable(name: "xyzzy", scope: !20, file: !1, line: 6, type: !10)286!22 = !DILocation(line: 1, scope: !20)287!23 = !{!21}288!30 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !33)289!31 = !DILocalVariable(name: "xyzzy", scope: !30, file: !1, line: 6, type: !10)290!32 = !DILocation(line: 1, scope: !30)291!33 = !{!31}292!40 = distinct !DISubprogram(name: "qux", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !46)293!41 = !DILocalVariable(name: "socks", scope: !40, file: !1, line: 6, type: !10)294!42 = !DILocation(line: 1, scope: !40)295!43 = distinct !DISubprogram(name: "inlined", scope: !1, file: !1, line: 5, type: !8, scopeLine: 5, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !47)296!44 = !DILocation(line: 0, scope: !43, inlinedAt: !42)297!45 = !DILocalVariable(name: "knees", scope: !43, file: !1, line: 6, type: !10)298!46 = !{!41}299!47 = !{!45}300