llvm/llvm/test/CodeGen/AArch64/GlobalISel/combine-with-flags.mir

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

---
name:            zext_trunc_nuw
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nuw
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: $x1 = COPY [[COPY]](s64)
    %0:_(s64) = COPY $x0
    %2:_(s32) = nuw G_TRUNC %0
    %3:_(s64) = G_ZEXT  %2
    $x1 = COPY %3
...
---
name:            zext_trunc_nsw
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nsw
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = nsw G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[TRUNC]](s32)
    ; CHECK-NEXT: $x1 = COPY [[ZEXT]](s64)
    %0:_(s64) = COPY $x0
    %2:_(s32) = nsw G_TRUNC %0
    %3:_(s64) = G_ZEXT  %2
    $x1 = COPY %3
...
---
name:            zext_trunc
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[ZEXT:%[0-9]+]]:_(s64) = G_ZEXT [[TRUNC]](s32)
    ; CHECK-NEXT: $x1 = COPY [[ZEXT]](s64)
    %0:_(s64) = COPY $x0
    %2:_(s32) = G_TRUNC %0
    %3:_(s64) = G_ZEXT  %2
    $x1 = COPY %3
...
---
name:            zext_trunc_nuw_vector
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nuw_vector
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s32)
    ; CHECK-NEXT: %trunc:_(<4 x s16>) = G_BUILD_VECTOR [[TRUNC]](s16), [[TRUNC1]](s16), [[TRUNC]](s16), [[TRUNC1]](s16)
    ; CHECK-NEXT: %zext:_(<4 x s32>) = G_ZEXT %trunc(<4 x s16>)
    ; CHECK-NEXT: $q0 = COPY %zext(<4 x s32>)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %0:_(s32) = COPY $w0
    %1:_(s32) = COPY $w1
    %2:_(s32) = COPY $w2
    %3:_(s32) = COPY $w3
    %bv0:_(<4 x s32>) = G_BUILD_VECTOR %0:_(s32), %1:_(s32), %0:_(s32), %1:_(s32)
    %trunc:_(<4 x s16>) = nuw G_TRUNC %bv0
    %zext:_(<4 x s32>) = G_ZEXT  %trunc
    $q0 = COPY %zext(<4 x s32>)
    RET_ReallyLR implicit $w0
...
---
name:            sext_trunc_nsw
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc_nsw
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: $x1 = COPY [[COPY]](s64)
    %0:_(s64) = COPY $x0
    %2:_(s32) = nsw G_TRUNC %0
    %3:_(s64) = G_SEXT  %2
    $x1 = COPY %3
...
---
name:            sext_trunc_nuw
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc_nuw
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = nuw G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[TRUNC]](s32)
    ; CHECK-NEXT: $x1 = COPY [[SEXT]](s64)
    %0:_(s64) = COPY $x0
    %2:_(s32) = nuw G_TRUNC %0
    %3:_(s64) = G_SEXT  %2
    $x1 = COPY %3
...
---
name:            sext_trunc
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[TRUNC]](s32)
    ; CHECK-NEXT: $x1 = COPY [[SEXT]](s64)
    %0:_(s64) = COPY $x0
    %2:_(s32) = G_TRUNC %0
    %3:_(s64) = G_SEXT  %2
    $x1 = COPY %3
...
---
name:            sext_trunc_nsw_types_wrong
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc_nsw_types_wrong
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = nsw G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: $w1 = COPY [[TRUNC]](s32)
    %0:_(s64) = COPY $x0
    %2:_(s16) = nsw G_TRUNC %0
    %3:_(s32) = G_SEXT  %2
    $w1 = COPY %3
...
---
name:            sext_trunc_nsw_nuw
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc_nsw_nuw
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: $x1 = COPY [[COPY]](s64)
    %0:_(s64) = COPY $x0
    %2:_(s32) = nsw nuw G_TRUNC %0
    %3:_(s64) = G_SEXT  %2
    $x1 = COPY %3
...
---
name:            sext_trunc_nsw_nuw_vector
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc_nsw_nuw_vector
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
    ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY $w2
    ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(s32) = COPY $w3
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s32)
    ; CHECK-NEXT: [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[COPY2]](s32)
    ; CHECK-NEXT: [[TRUNC3:%[0-9]+]]:_(s16) = G_TRUNC [[COPY3]](s32)
    ; CHECK-NEXT: %t:_(<4 x s16>) = G_BUILD_VECTOR [[TRUNC]](s16), [[TRUNC1]](s16), [[TRUNC2]](s16), [[TRUNC3]](s16)
    ; CHECK-NEXT: %s:_(<4 x s32>) = G_SEXT %t(<4 x s16>)
    ; CHECK-NEXT: $q0 = COPY %s(<4 x s32>)
    %0:_(s32) = COPY $w0
    %1:_(s32) = COPY $w1
    %2:_(s32) = COPY $w2
    %3:_(s32) = COPY $w3
    %bv0:_(<4 x s32>) = G_BUILD_VECTOR %0:_(s32), %1:_(s32), %2:_(s32), %3:_(s32)
    %t:_(<4 x s16>) = nsw nuw G_TRUNC %bv0
    %s:_(<4 x s32>) = G_SEXT  %t
    $q0 = COPY %s
...
---
name:            zext_trunc_vector
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_vector
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
    ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY $w2
    ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(s32) = COPY $w3
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s32)
    ; CHECK-NEXT: [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[COPY2]](s32)
    ; CHECK-NEXT: [[TRUNC3:%[0-9]+]]:_(s16) = G_TRUNC [[COPY3]](s32)
    ; CHECK-NEXT: %t:_(<4 x s16>) = G_BUILD_VECTOR [[TRUNC]](s16), [[TRUNC1]](s16), [[TRUNC2]](s16), [[TRUNC3]](s16)
    ; CHECK-NEXT: %z:_(<4 x s32>) = G_ZEXT %t(<4 x s16>)
    ; CHECK-NEXT: $q0 = COPY %z(<4 x s32>)
    %0:_(s32) = COPY $w0
    %1:_(s32) = COPY $w1
    %2:_(s32) = COPY $w2
    %3:_(s32) = COPY $w3
    %bv0:_(<4 x s32>) = G_BUILD_VECTOR %0:_(s32), %1:_(s32), %2:_(s32), %3:_(s32)
    %t:_(<4 x s16>) = G_TRUNC %bv0
    %z:_(<4 x s32>) = G_ZEXT  %t
    $q0 = COPY %z
...
---
name:            zext_trunc_nsw_vector
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nsw_vector
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
    ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY $w2
    ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(s32) = COPY $w3
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s32)
    ; CHECK-NEXT: [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[COPY2]](s32)
    ; CHECK-NEXT: [[TRUNC3:%[0-9]+]]:_(s16) = G_TRUNC [[COPY3]](s32)
    ; CHECK-NEXT: %t:_(<4 x s16>) = G_BUILD_VECTOR [[TRUNC]](s16), [[TRUNC1]](s16), [[TRUNC2]](s16), [[TRUNC3]](s16)
    ; CHECK-NEXT: %z:_(<4 x s32>) = G_ZEXT %t(<4 x s16>)
    ; CHECK-NEXT: $q0 = COPY %z(<4 x s32>)
    %0:_(s32) = COPY $w0
    %1:_(s32) = COPY $w1
    %2:_(s32) = COPY $w2
    %3:_(s32) = COPY $w3
    %bv0:_(<4 x s32>) = G_BUILD_VECTOR %0:_(s32), %1:_(s32), %2:_(s32), %3:_(s32)
    %t:_(<4 x s16>) = nsw G_TRUNC %bv0
    %z:_(<4 x s32>) = G_ZEXT  %t
    $q0 = COPY %z
...
---
name:            zext_trunc_nuw_vector2
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nuw_vector2
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
    ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s32) = COPY $w2
    ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(s32) = COPY $w3
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s32)
    ; CHECK-NEXT: [[TRUNC2:%[0-9]+]]:_(s16) = G_TRUNC [[COPY2]](s32)
    ; CHECK-NEXT: [[TRUNC3:%[0-9]+]]:_(s16) = G_TRUNC [[COPY3]](s32)
    ; CHECK-NEXT: %t:_(<4 x s16>) = G_BUILD_VECTOR [[TRUNC]](s16), [[TRUNC1]](s16), [[TRUNC2]](s16), [[TRUNC3]](s16)
    ; CHECK-NEXT: %z:_(<4 x s32>) = G_ZEXT %t(<4 x s16>)
    ; CHECK-NEXT: $q0 = COPY %z(<4 x s32>)
    %0:_(s32) = COPY $w0
    %1:_(s32) = COPY $w1
    %2:_(s32) = COPY $w2
    %3:_(s32) = COPY $w3
    %bv0:_(<4 x s32>) = G_BUILD_VECTOR %0:_(s32), %1:_(s32), %2:_(s32), %3:_(s32)
    %t:_(<4 x s16>) = nuw G_TRUNC %bv0
    %z:_(<4 x s32>) = G_ZEXT  %t
    $q0 = COPY %z
...
---
name:            zext_trunc_nuw_vector_wrong_type
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nuw_vector_wrong_type
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s64)
    ; CHECK-NEXT: %t:_(<2 x s16>) = G_BUILD_VECTOR [[TRUNC]](s16), [[TRUNC1]](s16)
    ; CHECK-NEXT: %z:_(<2 x s32>) = G_ZEXT %t(<2 x s16>)
    ; CHECK-NEXT: $d0 = COPY %z(<2 x s32>)
    %0:_(s64) = COPY $x0
    %1:_(s64) = COPY $x1
    %bv0:_(<2 x s64>) = G_BUILD_VECTOR %0:_(s64), %1:_(s64)
    %t:_(<2 x s16>) = nuw G_TRUNC %bv0
    %z:_(<2 x s32>) = G_ZEXT  %t
    $d0 = COPY %z
...
---
name:            zext_trunc_nuw_scalable_vector
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nuw_scalable_vector
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: %sv0:_(<vscale x 2 x s64>) = G_SPLAT_VECTOR [[COPY]](s64)
    ; CHECK-NEXT: $z0 = COPY %sv0(<vscale x 2 x s64>)
    %0:_(s64) = COPY $x0
    %1:_(s64) = COPY $x1
    %sv0:_(<vscale x 2 x s64>) = G_SPLAT_VECTOR %0:_(s64)
    %t:_(<vscale x 2 x s32>) = nuw G_TRUNC %sv0
    %z:_(<vscale x 2 x s64>) = G_ZEXT  %t
    $z0 = COPY %z
...
---
name:            zext_trunc_nuw_to_zext
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nuw_to_zext
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK-NEXT: %2:_(s64) = nneg G_ZEXT [[COPY]](s32)
    ; CHECK-NEXT: $x1 = COPY %2(s64)
    %0:_(s32) = COPY $w0
    %2:_(s16) = nuw G_TRUNC %0
    %3:_(s64) = G_ZEXT  %2
    $x1 = COPY %3
...
---
name:            zext_trunc_nuw_to_trunc
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: zext_trunc_nuw_to_trunc
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = nuw G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: $w1 = COPY [[TRUNC]](s32)
    %0:_(s64) = COPY $x0
    %2:_(s16) = nuw G_TRUNC %0
    %3:_(s32) = G_ZEXT  %2
    $w1 = COPY %3
...
---
name:            sext_trunc_nsw_to_sext
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc_nsw_to_sext
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
    ; CHECK-NEXT: [[SEXT:%[0-9]+]]:_(s64) = G_SEXT [[COPY]](s32)
    ; CHECK-NEXT: $x1 = COPY [[SEXT]](s64)
    %0:_(s32) = COPY $w0
    %2:_(s16) = nsw G_TRUNC %0
    %3:_(s64) = G_SEXT  %2
    $x1 = COPY %3
...
---
name:            sext_trunc_nsw_to_trunc
body:             |
  bb.0:
    liveins: $w0, $w1
    ; CHECK-LABEL: name: sext_trunc_nsw_to_trunc
    ; CHECK: liveins: $w0, $w1
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = nsw G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: $w1 = COPY [[TRUNC]](s32)
    %0:_(s64) = COPY $x0
    %2:_(s16) = nsw G_TRUNC %0
    %3:_(s32) = G_SEXT  %2
    $w1 = COPY %3
...