xref: /llvm-project/llvm/test/DebugInfo/X86/pr40427.ll (revision d53425e2a33a0ff7336c86d3f668b1855c47a6de)
1; RUN: llc -start-after=codegenprepare -stop-before=finalize-isel -o - < %s \
2; RUN:     -experimental-debug-variable-locations=false \
3; RUN: | FileCheck %s --check-prefixes=CHECK,DBGVALUE
4; RUN: llc -start-after=codegenprepare -stop-before=finalize-isel -o - < %s \
5; RUN:     -experimental-debug-variable-locations=true \
6; RUN: | FileCheck %s --check-prefixes=CHECK,INSTRREF
7;
8;; Test for correct placement of DBG_VALUE, which in PR40427 is placed before
9;; the load instruction it refers to. The circumstance replicated here is where
10;; two instructions in a row, trunc and add, begin with no-op Copy{To,From}Reg
11;; SDNodes that produce no instructions.
12;; The DBG_VALUE instruction should come immediately after the load instruction
13;; because the truncate is optimised out, and the DBG_VALUE should be placed
14;; in front of the first instruction that occurs after the dbg.value.
15;
16
17; CHECK: ![[DBGVAR:[0-9]+]] = !DILocalVariable(name: "bees",
18
19target triple = "x86_64-unknown-linux-gnu"
20
21define i16 @lolwat(i1 %spoons, ptr %bees, i16 %yellow, ptr %more) {
22entry:
23  br i1 %spoons, label %trueb, label %falseb
24trueb:
25  br label %block
26falseb:
27  br label %block
28block:
29; CHECK:      [[PHIREG:%[0-9]+]]:gr64 = PHI %6, %bb.2, %4, %bb.1
30; CHECK-NEXT: [[LOADR:%[0-9]+]]:gr16 = MOV16rm %0,
31; INSTRREF-SAME: debug-instr-number 1
32; DBGVALUE-NEXT: DBG_VALUE [[LOADR]], $noreg, ![[DBGVAR]]
33; INSTRREF-NEXT: DBG_INSTR_REF ![[DBGVAR]], {{.+}}, dbg-instr-ref(1, 0)
34; CHECK-NEXT: %{{[0-9]+}}:gr32 = IMPLICIT_DEF
35  %foo = phi ptr[%bees, %trueb], [%more, %falseb]
36  %ret = load i32, ptr %foo, !dbg !6
37  %cast = trunc i32 %ret to i16, !dbg !6
38  call void @llvm.dbg.value(metadata i16 %cast, metadata !1, metadata !DIExpression()), !dbg !6
39  %orly2 = add i16 %yellow, 1
40  br label %bb1
41bb1:
42  %cheese = add i16 %orly2, %cast
43  ret i16 %cheese, !dbg !6
44}
45
46declare void @llvm.dbg.value(metadata, metadata, metadata)
47
48!llvm.module.flags = !{!4}
49!llvm.dbg.cu = !{!2}
50!1 = !DILocalVariable(name: "bees", scope: !5, type: null)
51!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "beards", isOptimized: true, runtimeVersion: 4, emissionKind: FullDebug)
52!3 = !DIFile(filename: "bees.cpp", directory: "")
53!4 = !{i32 2, !"Debug Info Version", i32 3}
54!5 = distinct !DISubprogram(name: "nope", scope: !2, file: !3, line: 1, unit: !2)
55!6 = !DILocation(line: 0, scope: !5)
56!7 = !DILocalVariable(name: "flannel", scope: !5, type: null)
57