llvm/llvm/test/CodeGen/AArch64/GlobalISel/legalize-extracts.mir

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


---
name:            test_extracts_4
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $x0, $x1, $x2


    ; CHECK-LABEL: name: test_extracts_4
    ; CHECK: liveins: $x0, $x1, $x2
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x0
    ; CHECK-NEXT: [[EXTRACT:%[0-9]+]]:_(s32) = G_EXTRACT [[COPY]](s64), 32
    ; CHECK-NEXT: $w0 = COPY [[EXTRACT]](s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %0:_(s64) = COPY $x0
    %1:_(s64) = COPY $x1
    %2:_(s128) = G_MERGE_VALUES %0, %1
    %3:_(s32) = G_EXTRACT %2, 32
    $w0 = COPY %3
    RET_ReallyLR implicit $w0
...
---
name:            p0_from_s128
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $x0, $q0
    ; CHECK-LABEL: name: p0_from_s128
    ; CHECK: liveins: $x0, $q0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s128) = COPY $q0
    ; CHECK-NEXT: %extract:_(p0) = G_EXTRACT %val(s128), 0
    ; CHECK-NEXT: $x0 = COPY %extract(p0)
    ; CHECK-NEXT: RET_ReallyLR implicit $x0
    %val:_(s128) = COPY $q0
    %extract:_(p0) = G_EXTRACT %val, 0
    $x0 = COPY %extract
    RET_ReallyLR implicit $x0
...
---
name:            s64_from_s128
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $x0, $q0
    ; CHECK-LABEL: name: s64_from_s128
    ; CHECK: liveins: $x0, $q0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s128) = COPY $q0
    ; CHECK-NEXT: %extract:_(s64) = G_EXTRACT %val(s128), 0
    ; CHECK-NEXT: $x0 = COPY %extract(s64)
    ; CHECK-NEXT: RET_ReallyLR implicit $x0
    %val:_(s128) = COPY $q0
    %extract:_(s64) = G_EXTRACT %val, 0
    $x0 = COPY %extract
    RET_ReallyLR implicit $x0
...
---
name:            s32_from_s128
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $w0, $q0
    ; CHECK-LABEL: name: s32_from_s128
    ; CHECK: liveins: $w0, $q0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s128) = COPY $q0
    ; CHECK-NEXT: %extract:_(s32) = G_EXTRACT %val(s128), 0
    ; CHECK-NEXT: $w0 = COPY %extract(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %val:_(s128) = COPY $q0
    %extract:_(s32) = G_EXTRACT %val, 0
    $w0 = COPY %extract
    RET_ReallyLR implicit $w0
...
---
name:            s32_from_s64
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $w0
    ; CHECK-LABEL: name: s32_from_s64
    ; CHECK: liveins: $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s64) = COPY $x0
    ; CHECK-NEXT: %extract:_(s32) = G_EXTRACT %val(s64), 0
    ; CHECK-NEXT: $w0 = COPY %extract(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %val:_(s64) = COPY $x0
    %extract:_(s32) = G_EXTRACT %val, 0
    $w0 = COPY %extract
    RET_ReallyLR implicit $w0
...
---
name:            s32_from_p0
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $w0
    ; CHECK-LABEL: name: s32_from_p0
    ; CHECK: liveins: $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(p0) = COPY $x0
    ; CHECK-NEXT: %extract:_(s32) = G_EXTRACT %val(p0), 0
    ; CHECK-NEXT: $w0 = COPY %extract(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %val:_(p0) = COPY $x0
    %extract:_(s32) = G_EXTRACT %val, 0
    $w0 = COPY %extract
    RET_ReallyLR implicit $w0
...
---
name:            s16_from_s128
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $h0, $q0
    ; CHECK-LABEL: name: s16_from_s128
    ; CHECK: liveins: $h0, $q0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s128) = COPY $q0
    ; CHECK-NEXT: %extract:_(s16) = G_EXTRACT %val(s128), 0
    ; CHECK-NEXT: $h0 = COPY %extract(s16)
    ; CHECK-NEXT: RET_ReallyLR implicit $h0
    %val:_(s128) = COPY $q0
    %extract:_(s16) = G_EXTRACT %val, 0
    $h0 = COPY %extract
    RET_ReallyLR implicit $h0
...
---
name:            s16_from_s64
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $h0, $x0
    ; CHECK-LABEL: name: s16_from_s64
    ; CHECK: liveins: $h0, $x0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s64) = COPY $x0
    ; CHECK-NEXT: %extract:_(s16) = G_EXTRACT %val(s64), 0
    ; CHECK-NEXT: $h0 = COPY %extract(s16)
    ; CHECK-NEXT: RET_ReallyLR implicit $h0
    %val:_(s64) = COPY $x0
    %extract:_(s16) = G_EXTRACT %val, 0
    $h0 = COPY %extract
    RET_ReallyLR implicit $h0
...
---
name:            s16_from_s32
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $h0, $w0
    ; CHECK-LABEL: name: s16_from_s32
    ; CHECK: liveins: $h0, $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s32) = COPY $w0
    ; CHECK-NEXT: %extract:_(s16) = G_EXTRACT %val(s32), 0
    ; CHECK-NEXT: $h0 = COPY %extract(s16)
    ; CHECK-NEXT: RET_ReallyLR implicit $h0
    %val:_(s32) = COPY $w0
    %extract:_(s16) = G_EXTRACT %val, 0
    $h0 = COPY %extract
    RET_ReallyLR implicit $h0
...
---
name:            s8_from_s128
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $b0, $q0
    ; CHECK-LABEL: name: s8_from_s128
    ; CHECK: liveins: $b0, $q0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s128) = COPY $q0
    ; CHECK-NEXT: %extract:_(s8) = G_TRUNC %val(s128)
    ; CHECK-NEXT: $b0 = COPY %extract(s8)
    ; CHECK-NEXT: RET_ReallyLR implicit $b0
    %val:_(s128) = COPY $q0
    %extract:_(s8) = G_EXTRACT %val, 0
    $b0 = COPY %extract
    RET_ReallyLR implicit $b0
...
---
name:            s8_from_s64
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $b0, $x0
    ; CHECK-LABEL: name: s8_from_s64
    ; CHECK: liveins: $b0, $x0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s64) = COPY $x0
    ; CHECK-NEXT: %extract:_(s8) = G_TRUNC %val(s64)
    ; CHECK-NEXT: $b0 = COPY %extract(s8)
    ; CHECK-NEXT: RET_ReallyLR implicit $b0
    %val:_(s64) = COPY $x0
    %extract:_(s8) = G_EXTRACT %val, 0
    $b0 = COPY %extract
    RET_ReallyLR implicit $b0
...
---
name:            s8_from_s32
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $b0, $w0
    ; CHECK-LABEL: name: s8_from_s32
    ; CHECK: liveins: $b0, $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s32) = COPY $w0
    ; CHECK-NEXT: %extract:_(s8) = G_TRUNC %val(s32)
    ; CHECK-NEXT: $b0 = COPY %extract(s8)
    ; CHECK-NEXT: RET_ReallyLR implicit $b0
    %val:_(s32) = COPY $w0
    %extract:_(s8) = G_EXTRACT %val, 0
    $b0 = COPY %extract
    RET_ReallyLR implicit $b0
...
---
name:            s8_from_s16
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $b0, $h0
    ; CHECK-LABEL: name: s8_from_s16
    ; CHECK: liveins: $b0, $h0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s16) = COPY $h0
    ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT %val(s16)
    ; CHECK-NEXT: %extract:_(s8) = G_TRUNC [[ANYEXT]](s32)
    ; CHECK-NEXT: $b0 = COPY %extract(s8)
    ; CHECK-NEXT: RET_ReallyLR implicit $b0
    %val:_(s16) = COPY $h0
    %extract:_(s8) = G_EXTRACT %val, 0
    $b0 = COPY %extract
    RET_ReallyLR implicit $b0
...
---
name:            s1_from_s32
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $w0
    ; CHECK-LABEL: name: s1_from_s32
    ; CHECK: liveins: $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s32) = COPY $w0
    ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
    ; CHECK-NEXT: %ext:_(s32) = G_AND %val, [[C]]
    ; CHECK-NEXT: $w0 = COPY %ext(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %val:_(s32) = COPY $w0
    %extract:_(s1) = G_EXTRACT %val, 0
    %ext:_(s32) = G_ZEXT %extract
    $w0 = COPY %ext
    RET_ReallyLR implicit $w0
...
---
name:            s3_from_s32
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $w0
    ; CHECK-LABEL: name: s3_from_s32
    ; CHECK: liveins: $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s32) = COPY $w0
    ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 7
    ; CHECK-NEXT: %ext:_(s32) = G_AND %val, [[C]]
    ; CHECK-NEXT: $w0 = COPY %ext(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %val:_(s32) = COPY $w0
    %extract:_(s3) = G_EXTRACT %val, 0
    %ext:_(s32) = G_ZEXT %extract
    $w0 = COPY %ext
    RET_ReallyLR implicit $w0
...
---
name:            s3_from_s35
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $w0
    ; CHECK-LABEL: name: s3_from_s35
    ; CHECK: liveins: $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[DEF:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[DEF]](s64)
    ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 7
    ; CHECK-NEXT: %ext:_(s32) = G_AND [[TRUNC]], [[C]]
    ; CHECK-NEXT: $w0 = COPY %ext(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %val:_(s35) = G_IMPLICIT_DEF
    %extract:_(s3) = G_EXTRACT %val, 0
    %ext:_(s32) = G_ZEXT %extract
    $w0 = COPY %ext
    RET_ReallyLR implicit $w0
...
---
name:            s4_from_s32
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $w0
    ; CHECK-LABEL: name: s4_from_s32
    ; CHECK: liveins: $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %val:_(s32) = COPY $w0
    ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 15
    ; CHECK-NEXT: %ext:_(s32) = G_AND %val, [[C]]
    ; CHECK-NEXT: $w0 = COPY %ext(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %val:_(s32) = COPY $w0
    %extract:_(s4) = G_EXTRACT %val, 0
    %ext:_(s32) = G_ZEXT %extract
    $w0 = COPY %ext
    RET_ReallyLR implicit $w0
...
---
name:            s64_from_s264
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $x0
    ; CHECK-LABEL: name: s64_from_s264
    ; CHECK: liveins: $x0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[DEF:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
    ; CHECK-NEXT: %extract:_(s64) = COPY [[DEF]](s64)
    ; CHECK-NEXT: $x0 = COPY %extract(s64)
    ; CHECK-NEXT: RET_ReallyLR implicit $x0
    %val:_(s264) = G_IMPLICIT_DEF
    %extract:_(s64) = G_EXTRACT %val, 0
    $x0 = COPY %extract
    RET_ReallyLR implicit $x0
...
---
name:            s16_from_s144
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $h0
    ; CHECK-LABEL: name: s16_from_s144
    ; CHECK: liveins: $h0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %h0:_(s16) = COPY $h0
    ; CHECK-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES %h0(s16), %h0(s16), %h0(s16), %h0(s16)
    ; CHECK-NEXT: [[EXTRACT:%[0-9]+]]:_(s16) = G_EXTRACT [[MV]](s64), 1
    ; CHECK-NEXT: %extract:_(s16) = COPY [[EXTRACT]](s16)
    ; CHECK-NEXT: $h0 = COPY %extract(s16)
    ; CHECK-NEXT: RET_ReallyLR implicit $h0
    %h0:_(s16) = COPY $h0
    %val:_(s144) = G_MERGE_VALUES %h0, %h0, %h0, %h0, %h0, %h0, %h0, %h0, %h0
    %extract:_(s16) = G_EXTRACT %val, 1
    $h0 = COPY %extract
    RET_ReallyLR implicit $h0
...
---
name:            s32_from_s144
tracksRegLiveness: true
body: |
  bb.0:
    liveins: $h0, $w0
    ; CHECK-LABEL: name: s32_from_s144
    ; CHECK: liveins: $h0, $w0
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: %h0:_(s16) = COPY $h0
    ; CHECK-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES %h0(s16), %h0(s16), %h0(s16), %h0(s16)
    ; CHECK-NEXT: [[EXTRACT:%[0-9]+]]:_(s32) = G_EXTRACT [[MV]](s64), 1
    ; CHECK-NEXT: %extract:_(s32) = COPY [[EXTRACT]](s32)
    ; CHECK-NEXT: $w0 = COPY %extract(s32)
    ; CHECK-NEXT: RET_ReallyLR implicit $w0
    %h0:_(s16) = COPY $h0
    %val:_(s144) = G_MERGE_VALUES %h0, %h0, %h0, %h0, %h0, %h0, %h0, %h0, %h0
    %extract:_(s32) = G_EXTRACT %val, 1
    $w0 = COPY %extract
    RET_ReallyLR implicit $w0