| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 
 | # RUN: llc -run-pass wasm-reg-stackify %s -o - | FileCheck %s
--- |
  target triple = "wasm32-unknown-unknown"
  declare void @use(i32)
  define void @sink_same_bb() {
    unreachable
  }
  define void @clone_same_bb() {
    unreachable
  }
  define void @clone_different_bb_0() {
    unreachable
  }
  define void @clone_different_bb_1() {
    unreachable
  }
  !llvm.dbg.cu = !{!0}
  !llvm.module.flags = !{!2, !3, !4}
  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug)
  !1 = !DIFile(filename: "test.c", directory: "")
  !2 = !{i32 7, !"Dwarf Version", i32 5}
  !3 = !{i32 2, !"Debug Info Version", i32 3}
  !4 = !{i32 1, !"wchar_size", i32 4}
  !6 = distinct !DISubprogram(name: "sink_same_bb", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, unit: !0)
  !7 = !DISubroutineType(types: !8)
  !8 = !{null}
...
---
# Sinking within the same BB preserves the debug location.
# CHECK-LABEL: name: sink_same_bb
name: sink_same_bb
liveins:
  - { reg: '$arguments' }
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $arguments
    %0:i32 = CONST_I32 1, implicit-def $arguments, debug-location !DILocation(line:10, scope:!6)
    NOP implicit-def $arguments
    CALL @use, %0:i32, implicit-def $arguments
    RETURN implicit-def $arguments
  ; CHECK:      %0:i32 = CONST_I32 1, {{.*}}, debug-location !DILocation(line: 10
  ; CHECK-NEXT: CALL @use
...
---
# Cloning within the same BB preserves the debug location.
# CHECK-LABEL: name: clone_same_bb
name: clone_same_bb
liveins:
  - { reg: '$arguments' }
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $arguments
    %0:i32 = CONST_I32 1, implicit-def $arguments, debug-location !DILocation(line:10, scope:!6)
    NOP implicit-def $arguments
    CALL @use, %0:i32, implicit-def $arguments
    CALL @use, %0:i32, implicit-def $arguments
    RETURN implicit-def $arguments
  ; CHECK:      CALL @use
  ; CHECK-NEXT: %1:i32 = CONST_I32 1, {{.*}}, debug-location !DILocation(line: 10
  ; CHECK-NEXT: CALL @use
...
---
# Cloning to a different BB preserves the debug location in this case because
# the destination BB has an instruction that has the same debug location
# (test.c:10).
# CHECK-LABEL: name: clone_different_bb_0
name: clone_different_bb_0
liveins:
  - { reg: '$arguments' }
tracksRegLiveness: true
body: |
  bb.0:
    successors: %bb.1
    liveins: $arguments
    %0:i32 = CONST_I32 1, implicit-def $arguments, debug-location !DILocation(line:10, scope:!6)
    BR %bb.1, implicit-def $arguments
  bb.1:
  ; predecessors: %bb.0
    CALL @use, %0:i32, implicit-def $arguments, debug-location !DILocation(line:10, scope:!6)
    RETURN implicit-def $arguments
  ; CHECK: bb.1:
  ; CHECK:      %1:i32 = CONST_I32 1, {{.*}}, debug-location !DILocation(line: 10
  ; CHECK-NEXT: CALL @use, %1, {{.*}}, debug-location !DILocation(line: 10
...
---
# Cloning to a different BB does NOT preserve the debug location in this case
# because the destination BB doesn't have an instruction that has the same debug
# location (It has test.c:20 but not test.c:10).
# CHECK-LABEL: name: clone_different_bb_1
name: clone_different_bb_1
liveins:
  - { reg: '$arguments' }
tracksRegLiveness: true
body: |
  bb.0:
    successors: %bb.1
    liveins: $arguments
    %0:i32 = CONST_I32 1, implicit-def $arguments, debug-location !DILocation(line:10, scope:!6)
    BR %bb.1, implicit-def $arguments
  bb.1:
  ; predecessors: %bb.0
    CALL @use, %0:i32, implicit-def $arguments, debug-location !DILocation(line:20, scope:!6)
    RETURN implicit-def $arguments
  ; CHECK: bb.1:
  ; CHECK:      %1:i32 = CONST_I32 1
  ; CHECK-NOT:  %1:i32 = CONST_I32 1, {{.*}}, debug-location !DILocation(line: 10
  ; CHECK-NEXT: CALL @use, %1, {{.*}}, debug-location !DILocation(line: 20
...
 |