# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=aarch64-- -run-pass=early-ifcvt -stress-early-ifcvt %s -o - -verify-machineinstrs | FileCheck %s

# Test that "killed" flag on the same virtual register in merged blocks is
# removed for the first spliced block and is saved for the second one.
# Otherwise, register will be killed twice in a single block in the resulting
# MIR, which is incorrect.

---
name:            my_func
tracksRegLiveness: true
liveins:
  - { reg: '$w0', virtual-reg: '%0' }
body:             |
  ; CHECK-LABEL: name: my_func
  ; CHECK: bb.0.entry:
  ; CHECK-NEXT:   liveins: $w0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:gpr32common = COPY $w0
  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:gpr64common = COPY $x0
  ; CHECK-NEXT:   [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri [[COPY]], 1, 0, implicit-def $nzcv
  ; CHECK-NEXT:   [[ADDWri:%[0-9]+]]:gpr32common = ADDWri [[COPY]], 3, 0
  ; CHECK-NEXT:   [[SUBWri:%[0-9]+]]:gpr32common = SUBWri killed [[COPY]], 2, 0
  ; CHECK-NEXT:   [[CSELWr:%[0-9]+]]:gpr32common = CSELWr [[ADDWri]], [[SUBWri]], 1, implicit $nzcv
  ; CHECK-NEXT:   $x2 = COPY [[COPY1]]
  ; CHECK-NEXT:   RET_ReallyLR implicit $x2
  bb.0.entry:
    successors: %bb.1, %bb.2
    liveins: $w0

    %0:gpr32common = COPY $w0
    %1:gpr64common = COPY $x0
    %2:gpr32 = SUBSWri %0, 1, 0, implicit-def $nzcv
    Bcc 1, %bb.2, implicit $nzcv
    B %bb.1

  bb.1:
    successors: %bb.3

    %3:gpr32common = SUBWri killed %0, 2, 0
    B %bb.3

  bb.2:
    successors: %bb.3

    %4:gpr32common = ADDWri killed %0, 3, 0
    B %bb.3

  bb.3:
    %5:gpr32common = PHI %3, %bb.1, %4, %bb.2
    $x2 = COPY %1
    RET_ReallyLR implicit $x2

...
