llvm/llvm/test/CodeGen/X86/GlobalISel/x86_64-select-zext.mir

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

--- |

  define i8 @zext_i1_to_i8(i1 %val) {
    %res = zext i1 %val to i8
    ret i8 %res
  }

  define i16 @zext_i1_to_i16(i1 %val) {
    %res = zext i1 %val to i16
    ret i16 %res
  }

  define i32 @zext_i1_to_i32(i1 %val) {
    %res = zext i1 %val to i32
    ret i32 %res
  }

  define i64 @zext_i1_to_i64(i1 %val) {
    %res = zext i1 %val to i64
    ret i64 %res
  }

  define i16 @zext_i8_to_i16(i8 %val) {
    %res = zext i8 %val to i16
    ret i16 %res
  }

  define i32 @zext_i8_to_i32(i8 %val) {
    %res = zext i8 %val to i32
    ret i32 %res
  }

  define i64 @zext_i8_to_i64(i8 %val) {
    %res = zext i8 %val to i64
    ret i64 %res
  }

  define i32 @zext_i16_to_i32(i16 %val) {
    %res = zext i16 %val to i32
    ret i32 %res
  }

  define i64 @zext_i16_to_i64(i16 %val) {
    %res = zext i16 %val to i64
    ret i64 %res
  }

  define i64 @zext_i32_to_i64(i32 %val) {
    %res = zext i32 %val to i64
    ret i64 %res
  }

...
---
name:            zext_i1_to_i8
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i1_to_i8
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr8 = COPY [[COPY]].sub_8bit
    ; CHECK-NEXT: [[AND8ri:%[0-9]+]]:gr8 = AND8ri [[COPY1]], 1, implicit-def dead $eflags
    ; CHECK-NEXT: $al = COPY [[AND8ri]]
    ; CHECK-NEXT: RET 0, implicit $al
    %1:gpr(s32) = COPY $edi
    %3:gpr(s8) = G_CONSTANT i8 1
    %4:gpr(s8) = G_TRUNC %1(s32)
    %2:gpr(s8) = G_AND %4, %3
    $al = COPY %2(s8)
    RET 0, implicit $al

...
---
name:            zext_i1_to_i16
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i1_to_i16
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr16 = COPY [[COPY]].sub_16bit
    ; CHECK-NEXT: [[AND16ri:%[0-9]+]]:gr16 = AND16ri [[COPY1]], 1, implicit-def dead $eflags
    ; CHECK-NEXT: $ax = COPY [[AND16ri]]
    ; CHECK-NEXT: RET 0, implicit $ax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s16) = G_CONSTANT i16 1
    %4:gpr(s16) = G_TRUNC %1(s32)
    %2:gpr(s16) = G_AND %4, %3
    $ax = COPY %2(s16)
    RET 0, implicit $ax

...
---
name:            zext_i1_to_i32
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i1_to_i32
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[AND32ri:%[0-9]+]]:gr32 = AND32ri [[COPY]], 1, implicit-def dead $eflags
    ; CHECK-NEXT: $eax = COPY [[AND32ri]]
    ; CHECK-NEXT: RET 0, implicit $eax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s32) = G_CONSTANT i32 1
    %4:gpr(s32) = COPY %1(s32)
    %2:gpr(s32) = G_AND %4, %3
    $eax = COPY %2(s32)
    RET 0, implicit $eax

...
---
name:            zext_i1_to_i64
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i1_to_i64
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[DEF:%[0-9]+]]:gr64 = IMPLICIT_DEF
    ; CHECK-NEXT: [[INSERT_SUBREG:%[0-9]+]]:gr64 = INSERT_SUBREG [[DEF]], [[COPY]], %subreg.sub_32bit
    ; CHECK-NEXT: [[AND64ri32_:%[0-9]+]]:gr64 = AND64ri32 [[INSERT_SUBREG]], 1, implicit-def dead $eflags
    ; CHECK-NEXT: $rax = COPY [[AND64ri32_]]
    ; CHECK-NEXT: RET 0, implicit $rax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s64) = G_CONSTANT i64 1
    %4:gpr(s64) = G_ANYEXT %1(s32)
    %2:gpr(s64) = G_AND %4, %3
    $rax = COPY %2(s64)
    RET 0, implicit $rax

...
---
name:            zext_i8_to_i16
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i8_to_i16
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr16 = COPY [[COPY]].sub_16bit
    ; CHECK-NEXT: [[COPY2:%[0-9]+]]:gr8 = COPY [[COPY1]].sub_8bit
    ; CHECK-NEXT: [[MOVZX32rr8_:%[0-9]+]]:gr32 = MOVZX32rr8 [[COPY2]]
    ; CHECK-NEXT: [[COPY3:%[0-9]+]]:gr16 = COPY [[MOVZX32rr8_]].sub_16bit
    ; CHECK-NEXT: $ax = COPY [[COPY3]]
    ; CHECK-NEXT: RET 0, implicit $ax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s16) = G_CONSTANT i16 255
    %4:gpr(s16) = G_TRUNC %1(s32)
    %2:gpr(s16) = G_AND %4, %3
    $ax = COPY %2(s16)
    RET 0, implicit $ax

...
---
name:            zext_i8_to_i32
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i8_to_i32
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr8 = COPY [[COPY]].sub_8bit
    ; CHECK-NEXT: [[MOVZX32rr8_:%[0-9]+]]:gr32 = MOVZX32rr8 [[COPY1]]
    ; CHECK-NEXT: $eax = COPY [[MOVZX32rr8_]]
    ; CHECK-NEXT: RET 0, implicit $eax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s32) = G_CONSTANT i32 255
    %4:gpr(s32) = COPY %1(s32)
    %2:gpr(s32) = G_AND %4, %3
    $eax = COPY %2(s32)
    RET 0, implicit $eax

...
---
name:            zext_i8_to_i64
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i8_to_i64
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[DEF:%[0-9]+]]:gr64 = IMPLICIT_DEF
    ; CHECK-NEXT: [[INSERT_SUBREG:%[0-9]+]]:gr64 = INSERT_SUBREG [[DEF]], [[COPY]], %subreg.sub_32bit
    ; CHECK-NEXT: [[AND64ri32_:%[0-9]+]]:gr64 = AND64ri32 [[INSERT_SUBREG]], 255, implicit-def dead $eflags
    ; CHECK-NEXT: $rax = COPY [[AND64ri32_]]
    ; CHECK-NEXT: RET 0, implicit $rax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s64) = G_CONSTANT i64 255
    %4:gpr(s64) = G_ANYEXT %1(s32)
    %2:gpr(s64) = G_AND %4, %3
    $rax = COPY %2(s64)
    RET 0, implicit $rax

...
---
name:            zext_i16_to_i32
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i16_to_i32
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:gr16 = COPY [[COPY]].sub_16bit
    ; CHECK-NEXT: [[MOVZX32rr16_:%[0-9]+]]:gr32 = MOVZX32rr16 [[COPY1]]
    ; CHECK-NEXT: $eax = COPY [[MOVZX32rr16_]]
    ; CHECK-NEXT: RET 0, implicit $eax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s32) = G_CONSTANT i32 65535
    %4:gpr(s32) = COPY %1(s32)
    %2:gpr(s32) = G_AND %4, %3
    $eax = COPY %2(s32)
    RET 0, implicit $eax

...
---
name:            zext_i16_to_i64
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: _ }
  - { id: 1, class: gpr }
  - { id: 2, class: gpr }
  - { id: 3, class: gpr }
  - { id: 4, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i16_to_i64
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[DEF:%[0-9]+]]:gr64 = IMPLICIT_DEF
    ; CHECK-NEXT: [[INSERT_SUBREG:%[0-9]+]]:gr64 = INSERT_SUBREG [[DEF]], [[COPY]], %subreg.sub_32bit
    ; CHECK-NEXT: [[AND64ri32_:%[0-9]+]]:gr64 = AND64ri32 [[INSERT_SUBREG]], 65535, implicit-def dead $eflags
    ; CHECK-NEXT: $rax = COPY [[AND64ri32_]]
    ; CHECK-NEXT: RET 0, implicit $rax
    %1:gpr(s32) = COPY $edi
    %3:gpr(s64) = G_CONSTANT i64 65535
    %4:gpr(s64) = G_ANYEXT %1(s32)
    %2:gpr(s64) = G_AND %4, %3
    $rax = COPY %2(s64)
    RET 0, implicit $rax

...
---
name:            zext_i32_to_i64
alignment:       16
legalized:       true
regBankSelected: true
tracksRegLiveness: true
registers:
  - { id: 0, class: gpr }
  - { id: 1, class: gpr }
body:             |
  bb.1 (%ir-block.0):
    liveins: $edi

    ; CHECK-LABEL: name: zext_i32_to_i64
    ; CHECK: liveins: $edi
    ; CHECK-NEXT: {{  $}}
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:gr32 = COPY $edi
    ; CHECK-NEXT: [[MOV32rr:%[0-9]+]]:gr32 = MOV32rr [[COPY]]
    ; CHECK-NEXT: [[SUBREG_TO_REG:%[0-9]+]]:gr64 = SUBREG_TO_REG 0, [[MOV32rr]], %subreg.sub_32bit
    ; CHECK-NEXT: $rax = COPY [[SUBREG_TO_REG]]
    ; CHECK-NEXT: RET 0, implicit $rax
    %0:gpr(s32) = COPY $edi
    %1:gpr(s64) = G_ZEXT %0(s32)
    $rax = COPY %1(s64)
    RET 0, implicit $rax

...