llvm/llvm/test/CodeGen/AArch64/sink-and-fold-drop-dbg.mir

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
# RUN: llc --aarch64-enable-sink-fold=true --run-pass=machine-sink %s -o - | FileCheck %s
--- |
  source_filename = "dbg.c"
  target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
  target triple = "aarch64-unknown-linux"

  define dso_local void @g(i32 noundef %x) local_unnamed_addr !dbg !11 {
  entry:
    call void @llvm.dbg.value(metadata i32 %x, metadata !16, metadata !DIExpression()), !dbg !20
    %add = add nsw i32 %x, 1, !dbg !21
    call void @llvm.dbg.value(metadata i32 %add, metadata !17, metadata !DIExpression()), !dbg !20
    call void @llvm.dbg.value(metadata i32 %add, metadata !18, metadata !DIExpression()), !dbg !20
    %call = tail call i32 @f(i32 noundef %add), !dbg !22
    call void @llvm.dbg.value(metadata i32 %add, metadata !19, metadata !DIExpression()), !dbg !20
    %call1 = tail call i32 @f(i32 noundef %add), !dbg !23
    ret void, !dbg !24
  }

  declare !dbg !25 i32 @f(i32 noundef)

  declare void @llvm.dbg.value(metadata, metadata, metadata)

  !llvm.dbg.cu = !{!0}
  !llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8, !9}
  !llvm.ident = !{!10}

  !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 18.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
  !1 = !DIFile(filename: "dbg.c", directory: "/home/sweet", checksumkind: CSK_MD5, checksum: "b6bd7ad2140c696af9201a17ab73c918")
  !2 = !{i32 7, !"Dwarf Version", i32 5}
  !3 = !{i32 2, !"Debug Info Version", i32 3}
  !4 = !{i32 1, !"wchar_size", i32 4}
  !5 = !{i32 8, !"PIC Level", i32 2}
  !6 = !{i32 7, !"PIE Level", i32 2}
  !7 = !{i32 7, !"uwtable", i32 2}
  !8 = !{i32 7, !"frame-pointer", i32 1}
  !9 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
  !10 = !{!"clang version 18.0.0"}
  !11 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
  !12 = !DISubroutineType(types: !13)
  !13 = !{null, !14}
  !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
  !15 = !{!16, !17, !18, !19}
  !16 = !DILocalVariable(name: "x", arg: 1, scope: !11, file: !1, line: 3, type: !14)
  !17 = !DILocalVariable(name: "y", scope: !11, file: !1, line: 4, type: !14)
  !18 = !DILocalVariable(name: "t0", scope: !11, file: !1, line: 6, type: !14)
  !19 = !DILocalVariable(name: "t1", scope: !11, file: !1, line: 9, type: !14)
  !20 = !DILocation(line: 0, scope: !11)
  !21 = !DILocation(line: 4, column: 13, scope: !11)
  !22 = !DILocation(line: 7, column: 3, scope: !11)
  !23 = !DILocation(line: 10, column: 3, scope: !11)
  !24 = !DILocation(line: 11, column: 1, scope: !11)
  !25 = !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !26, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
  !26 = !DISubroutineType(types: !27)
  !27 = !{!14, !14}

...
---
name:            g
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
failedISel:      false
tracksRegLiveness: true
hasWinCFI:       false
callsEHReturn:   false
callsUnwindInit: false
hasEHCatchret:   false
hasEHScopes:     false
hasEHFunclets:   false
isOutlined:      false
debugInstrRef:   false
failsVerification: false
tracksDebugUserValues: false
registers:
  - { id: 0, class: gpr32common, preferred-register: '' }
  - { id: 1, class: gpr32sp, preferred-register: '' }
  - { id: 2, class: gpr32all, preferred-register: '' }
liveins:
  - { reg: '$w0', virtual-reg: '%0' }
frameInfo:
  isFrameAddressTaken: false
  isReturnAddressTaken: false
  hasStackMap:     false
  hasPatchPoint:   false
  stackSize:       0
  offsetAdjustment: 0
  maxAlignment:    1
  adjustsStack:    true
  hasCalls:        true
  stackProtector:  ''
  functionContext: ''
  maxCallFrameSize: 0
  cvBytesOfCalleeSavedRegisters: 0
  hasOpaqueSPAdjustment: false
  hasVAStart:      false
  hasMustTailInVarArgFunc: false
  hasTailCall:     true
  localFrameSize:  0
  savePoint:       ''
  restorePoint:    ''
fixedStack:      []
stack:           []
entry_values:    []
callSites:       []
debugValueSubstitutions: []
constants:       []
machineFunctionInfo: {}
body:             |
  bb.0.entry:
    liveins: $w0

    ; CHECK-LABEL: name: g
    ; CHECK: liveins: $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: DBG_VALUE $w0, $noreg, !16, !DIExpression(), debug-location !20
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr32common = COPY $w0
    ; CHECK-NEXT: DBG_VALUE [[COPY]], $noreg, !16, !DIExpression(), debug-location !20
    ; CHECK-NEXT: DBG_VALUE $noreg, $noreg, !17, !DIExpression(), debug-location !20
    ; CHECK-NEXT: DBG_VALUE $noreg, $noreg, !18, !DIExpression(), debug-location !20
    ; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp, debug-location !22
    ; CHECK-NEXT: $w0 = nsw ADDWri [[COPY]], 1, 0, debug-location !21
    ; CHECK-NEXT: BL @f, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0, debug-location !22
    ; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp, debug-location !22
    ; CHECK-NEXT: DBG_VALUE $noreg, $noreg, !19, !DIExpression(), debug-location !20
    ; CHECK-NEXT: $w0 = nsw ADDWri [[COPY]], 1, 0, debug-location !21
    ; CHECK-NEXT: TCRETURNdi @f, 0, csr_aarch64_aapcs, implicit $sp, implicit $w0, debug-location !23
    DBG_VALUE $w0, $noreg, !16, !DIExpression(), debug-location !20
    %0:gpr32common = COPY $w0
    DBG_VALUE %0, $noreg, !16, !DIExpression(), debug-location !20
    %1:gpr32sp = nsw ADDWri %0, 1, 0, debug-location !21
    DBG_VALUE %1, $noreg, !17, !DIExpression(), debug-location !20
    DBG_VALUE %1, $noreg, !18, !DIExpression(), debug-location !20
    ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp, debug-location !22
    $w0 = COPY %1, debug-location !22
    BL @f, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0, debug-location !22
    ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp, debug-location !22
    DBG_VALUE %1, $noreg, !19, !DIExpression(), debug-location !20
    $w0 = COPY %1, debug-location !23
    TCRETURNdi @f, 0, csr_aarch64_aapcs, implicit $sp, implicit $w0, debug-location !23

...