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