reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    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
# RUN: llc -mtriple=x86_64-unknown-unknown -run-pass=machine-sink -o - %s | FileCheck %s
# Check various things when we sink machine instructions:
#   a) DBG_VALUEs should sink with defs
#   b) Undefs should be left behind
#   c) DBG_VALUEs not immediately following the defining inst should sink too
#   d) If we generate debug-use-before-defs through sinking, and can copy
#      propagate to a different value, we should do that.
--- |
  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
  target triple = "x86_64-unknown-linux-gnu"

  @x = common local_unnamed_addr global i32 0, align 4, !dbg !0

  ; Function Attrs: noreturn nounwind uwtable
  define void @Process(i32* nocapture readonly %p) local_unnamed_addr !dbg !9 {
  ; Stripped
  entry:
    br label %nou
  nou:
    br label %exit
  exit:
    ret void
  }

  ; Function Attrs: nounwind readnone
  declare void @llvm.dbg.value(metadata, i64, metadata, metadata)

  !llvm.dbg.cu = !{!1}
  !llvm.module.flags = !{!6, !7}
  !llvm.ident = !{!8}

  !0 = !DIGlobalVariableExpression(var: !DIGlobalVariable(name: "x", scope: !1, file: !2, line: 1, type: !5, isLocal: false, isDefinition: true), expr: !DIExpression())
  !1 = distinct !DICompileUnit(language: DW_LANG_C99, file: !2, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3, globals: !4)
  !2 = !DIFile(filename: "t.c", directory: "")
  !3 = !{}
  !4 = !{!0}
  !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !6 = !{i32 2, !"Dwarf Version", i32 4}
  !7 = !{i32 2, !"Debug Info Version", i32 3}
  !8 = !{!"clang version 4.0.0 "}
  !9 = distinct !DISubprogram(name: "Process", scope: !2, file: !2, line: 2, type: !10, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !1, retainedNodes: !15)
  !10 = !DISubroutineType(types: !11)
  !11 = !{null, !12}
  !12 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
  !13 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14)
  !14 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
  !15 = !{!16}
  !16 = !DILocalVariable(name: "p", arg: 1, scope: !9, file: !2, line: 2, type: !12)
  !17 = !DIExpression()
  !18 = !DILocation(line: 2, column: 34, scope: !9)
  !28 = !DILexicalBlockFile(scope: !9, file: !2, discriminator: 1)

  ; CHECK: [[VARNUM:![0-9]+]] = !DILocalVariable(name: "p",

...
---
name:            Process
tracksRegLiveness: true
liveins:
  - { reg: '$rdi', virtual-reg: '%2' }
  - { reg: '$rsi', virtual-reg: '%2' }
body:             |
  bb.0.entry:
    successors: %bb.1.nou(0x80000000), %bb.2.exit
    liveins: $rdi, $esi

    ; This block should have the vreg copy sunk from it, the DBG_VALUE with it,
    ; and a copy-prop'd DBG_VALUE left over.
    ; CHECK-LABEL: bb.0.entry:
    ; CHECK:       [[ARG0VREG:%[0-9]+]]:gr64 = COPY $rdi
    ; CHECK-NEXT:  CMP32ri $esi, 0
    ; CHECK-NEXT:  DBG_VALUE [[ARG0VREG]], $noreg, [[VARNUM]]
    ; CHECK-NEXT:  JCC_1 %bb.1, 4
    ; CHECK-NEXT:  JMP_1

    %2:gr64 = COPY $rdi
    %5:gr64 = COPY %2
    CMP32ri $esi, 0, implicit-def $eflags
    DBG_VALUE %5, $noreg, !16, !17, debug-location !18
    JCC_1 %bb.1.nou, 4, implicit $eflags
    JMP_1 %bb.2.exit

  bb.1.nou:
    successors: %bb.2.exit(0x80000000)

    ; This block should receive the sunk copy and DBG_VALUE
    ; CHECK-LABEL: bb.1.nou:
    ; CHECK:       [[SUNKVREG:%[0-9]+]]:gr64 = COPY [[ARG0VREG]]
    ; CHECK-NEXT:  DBG_VALUE [[SUNKVREG]], $noreg, [[VARNUM]]
    ; CHECK-NEXT:  ADD64ri8
    ; CHECK-NEXT:  JMP_1
    %1:gr64 = ADD64ri8 %5, 4, implicit-def dead $eflags
    JMP_1 %bb.2.exit

  bb.2.exit:
    ; The DBG_VALUE below should have its operand copy-propagated after
    ; the copy to %5 is sunk.
    ; CHECK-LABEL: bb.2.exit:
    ; CHECK:       DBG_VALUE [[ARG0VREG]], $noreg, [[VARNUM]]
    ; CHECK-NEXT:  $rax = MOV64rr [[ARG0VREG]]
    ; CHECK-NEXT:  RET 0
    DBG_VALUE %5, _, !16, !17, debug-location !18
    $rax = MOV64rr %2
    RET 0
...