116 lines · plain
1; RUN: llc -mtriple=x86_64-unknown-unknown -start-after=codegenprepare -stop-before=finalize-isel %s -o - -experimental-debug-variable-locations=false | FileCheck %s --check-prefixes=COMMON,CHECK2; RUN: llc -mtriple=x86_64-unknown-unknown -start-after=codegenprepare -stop-before=finalize-isel %s -o - -experimental-debug-variable-locations=true | FileCheck %s --check-prefixes=COMMON,INSTRREF3 4 5; Test the movement of dbg.values of arguments. SelectionDAG tries to be6; helpful and places DBG_VALUEs of Arguments at the start of functions.7; Unfortunately, this doesn't necessarily make sense, as one can specify an8; Argument IR Value as a variable location anywhere in the program.9;10; Distinguish cases where we want to hoist DBG_VALUEs, and those where we11; don't, by whether the referred to variable is a parameter to the current12; function. In the test below, 'xyzzy' is a parameter to an inlined function,13; but should not be hoisted to the start of the function.14;15; With instruction referencing, accuracy becomes more important than coverage,16; so debug instructions are placed wherever they were in the IR.17;18; Original test case, in which 'xyzzy' became unavailable because its DBG_VALUE19; landed far from any uses, compiled "clang -O2 -g" with inlining,20;21; int ext(void);22;23; int24; foo(int xyzzy)25; {26; xyzzy = ext() * xyzzy;27; xyzzy += 1;28; ext();29; return xyzzy;30; }31;32; int33; bar(int baz, int qux)34; {35; int fish;36; switch (qux) {37; case 12: fish = 8; break;38; case 848: fish = 0; break;39; case 99999: fish = -1; break;40; default: fish = 12;41; }42; qux %= fish;43; qux += foo(baz);44; return qux;45; }46 47; COMMON: [[BAZVAR:![0-9]+]] = !DILocalVariable(name: "baz",48; COMMON: [[XYZVAR:![0-9]+]] = !DILocalVariable(name: "xyzzy",49 50; Start of MIR function block,51; CHECK-LABEL: body52; Expect DBG_VALUE of physreg,53; CHECK: DBG_VALUE $edi, $noreg, [[BAZVAR]]54; Expect DBG_VALUE of virtreg,55; CHECK: DBG_VALUE [[ARGREG:%[0-9]+]], $noreg, [[BAZVAR]]56; Label for next block,57; CHECK-LABEL: bb.1.next58; Correctly place dbg.value in the 'next' block.59; CHECK: DBG_VALUE [[ARGREG]], $noreg, [[XYZVAR]]60 61; INSTRREF-LABEL: body62; INSTRREF: DBG_PHI $edi, 163; INSTRREF: DBG_VALUE $edi, $noreg, [[BAZVAR]]64; INSTRREF-LABEL: bb.1.next65; INSTRREF: DBG_INSTR_REF [[XYZVAR]], {{.+}}, dbg-instr-ref(1, 0)66 67target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"68target triple = "x86_64-unknown-linux-gnu"69 70declare i32 @ext()71 72define dso_local i32 @bar(i32, i32) local_unnamed_addr !dbg !7 {73 %3 = srem i32 %1, %0, !dbg !1574 call void @llvm.dbg.value(metadata i32 %0, metadata !12, metadata !DIExpression()), !dbg !1675 br label %next76 77next: ; preds = %278 call void @llvm.dbg.value(metadata i32 %0, metadata !17, metadata !DIExpression()), !dbg !2279 %4 = tail call i32 @ext(), !dbg !2480 %5 = mul nsw i32 %3, %4, !dbg !2581 %6 = add i32 %5, %0, !dbg !2582 ret i32 %6, !dbg !2583}84 85; Function Attrs: nounwind readnone speculatable86declare void @llvm.dbg.value(metadata, metadata, metadata)87 88!llvm.dbg.cu = !{!0}89!llvm.module.flags = !{!3, !4, !5}90!llvm.ident = !{!6}91 92!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !2, nameTableKind: None)93!1 = !DIFile(filename: "test.c", directory: ".")94!2 = !{}95!3 = !{i32 2, !"Dwarf Version", i32 4}96!4 = !{i32 2, !"Debug Info Version", i32 3}97!5 = !{i32 1, !"wchar_size", i32 4}98!6 = !{!"clang version 8.0.0"}99!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 19, type: !8, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)100!8 = !DISubroutineType(types: !9)101!9 = !{!10, !10, !10}102!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)103!11 = !{!12}104!12 = !DILocalVariable(name: "baz", arg: 1, scope: !7, file: !1, line: 19, type: !10)105!15 = !DILocation(line: 35, column: 7, scope: !7)106!16 = !DILocation(line: 19, column: 9, scope: !7)107!17 = !DILocalVariable(name: "xyzzy", arg: 1, scope: !18, file: !1, line: 10, type: !10)108!18 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 10, type: !19, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !21)109!19 = !DISubroutineType(types: !20)110!20 = !{!10, !10}111!21 = !{!17}112!22 = !DILocation(line: 10, column: 9, scope: !18, inlinedAt: !23)113!23 = distinct !DILocation(line: 36, column: 10, scope: !7)114!24 = !DILocation(line: 12, column: 11, scope: !18, inlinedAt: !23)115!25 = !DILocation(line: 37, column: 3, scope: !7)116