llvm/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/legalize-mul-ext-rv64.mir

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mattr=+m -mtriple=riscv64 -run-pass=legalizer %s -o - \
# RUN: | FileCheck %s
# RUN: llc -mattr=+zmmul -mtriple=riscv64 -run-pass=legalizer %s -o - \
# RUN: | FileCheck %s
---
name:            mul_i8
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i8
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s32) = G_MUL [[TRUNC]], [[TRUNC1]]
    ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[MUL]](s32)
    ; CHECK-NEXT: $x10 = COPY [[ANYEXT]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10
    %0:_(s64) = COPY $x10
    %1:_(s64) = COPY $x11
    %2:_(s8) = G_TRUNC %0(s64)
    %3:_(s8) = G_TRUNC %1(s64)
    %4:_(s8) = G_MUL %2, %3
    %5:_(s64) = G_ANYEXT %4(s8)
    $x10 = COPY %5(s64)
    PseudoRET implicit $x10

...
---
name:            mul_i15
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i15
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s32) = G_MUL [[TRUNC]], [[TRUNC1]]
    ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[MUL]](s32)
    ; CHECK-NEXT: $x10 = COPY [[ANYEXT]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10
    %0:_(s64) = COPY $x10
    %1:_(s64) = COPY $x11
    %2:_(s15) = G_TRUNC %0(s64)
    %3:_(s15) = G_TRUNC %1(s64)
    %4:_(s15) = G_MUL %2, %3
    %5:_(s64) = G_ANYEXT %4(s15)
    $x10 = COPY %5(s64)
    PseudoRET implicit $x10

...
---
name:            mul_i16
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i16
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s32) = G_MUL [[TRUNC]], [[TRUNC1]]
    ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[MUL]](s32)
    ; CHECK-NEXT: $x10 = COPY [[ANYEXT]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10
    %0:_(s64) = COPY $x10
    %1:_(s64) = COPY $x11
    %2:_(s16) = G_TRUNC %0(s64)
    %3:_(s16) = G_TRUNC %1(s64)
    %4:_(s16) = G_MUL %2, %3
    %5:_(s64) = G_ANYEXT %4(s16)
    $x10 = COPY %5(s64)
    PseudoRET implicit $x10

...
---
name:            mul_i32
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i32
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
    ; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s32) = G_TRUNC [[COPY]](s64)
    ; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s32) = G_TRUNC [[COPY1]](s64)
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s32) = G_MUL [[TRUNC]], [[TRUNC1]]
    ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s64) = G_ANYEXT [[MUL]](s32)
    ; CHECK-NEXT: $x10 = COPY [[ANYEXT]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10
    %0:_(s64) = COPY $x10
    %1:_(s64) = COPY $x11
    %2:_(s32) = G_TRUNC %0(s64)
    %3:_(s32) = G_TRUNC %1(s64)
    %4:_(s32) = G_MUL %2, %3
    %5:_(s64) = G_ANYEXT %4(s32)
    $x10 = COPY %5(s64)
    PseudoRET implicit $x10

...
---
name:            mul_i64
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i64
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[COPY]], [[COPY1]]
    ; CHECK-NEXT: $x10 = COPY [[MUL]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10
    %0:_(s64) = COPY $x10
    %1:_(s64) = COPY $x11
    %2:_(s64) = G_MUL %0, %1
    $x10 = COPY %2(s64)
    PseudoRET implicit $x10

...
---
name:            mul_i72
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i72
    ; CHECK: %xlo:_(s64) = COPY $x10
    ; CHECK-NEXT: %xhi:_(s64) = COPY $x11
    ; CHECK-NEXT: %ylo:_(s64) = COPY $x12
    ; CHECK-NEXT: %yhi:_(s64) = COPY $x13
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL %xlo, %ylo
    ; CHECK-NEXT: [[MUL1:%[0-9]+]]:_(s64) = G_MUL %xhi, %ylo
    ; CHECK-NEXT: [[MUL2:%[0-9]+]]:_(s64) = G_MUL %xlo, %yhi
    ; CHECK-NEXT: [[UMULH:%[0-9]+]]:_(s64) = G_UMULH %xlo, %ylo
    ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s64) = G_ADD [[MUL1]], [[MUL2]]
    ; CHECK-NEXT: [[ADD1:%[0-9]+]]:_(s64) = G_ADD [[ADD]], [[UMULH]]
    ; CHECK-NEXT: $x10 = COPY [[MUL]](s64)
    ; CHECK-NEXT: $x11 = COPY [[ADD1]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10, implicit $x11
    %xlo:_(s64) = COPY $x10
    %xhi:_(s64) = COPY $x11
    %ylo:_(s64) = COPY $x12
    %yhi:_(s64) = COPY $x13
    %x0:_(s128) = G_MERGE_VALUES %xlo(s64), %xhi(s64)
    %y0:_(s128) = G_MERGE_VALUES %ylo(s64), %yhi(s64)
    %x:_(s72) = G_TRUNC %x0(s128)
    %y:_(s72) = G_TRUNC %y0(s128)
    %z:_(s72) = G_MUL %x, %y
    %z0:_(s128) = G_ANYEXT %z(s72)
    %zlo:_(s64), %zhi:_(s64) = G_UNMERGE_VALUES %z0(s128)
    $x10 = COPY %zlo(s64)
    $x11 = COPY %zhi(s64)
    PseudoRET implicit $x10, implicit $x11

...
---
name:            mul_i128
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i128
    ; CHECK: %lo1:_(s64) = COPY $x10
    ; CHECK-NEXT: %hi1:_(s64) = COPY $x11
    ; CHECK-NEXT: %lo2:_(s64) = COPY $x12
    ; CHECK-NEXT: %hi2:_(s64) = COPY $x13
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL %lo1, %lo2
    ; CHECK-NEXT: [[MUL1:%[0-9]+]]:_(s64) = G_MUL %hi1, %lo2
    ; CHECK-NEXT: [[MUL2:%[0-9]+]]:_(s64) = G_MUL %lo1, %hi2
    ; CHECK-NEXT: [[UMULH:%[0-9]+]]:_(s64) = G_UMULH %lo1, %lo2
    ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s64) = G_ADD [[MUL1]], [[MUL2]]
    ; CHECK-NEXT: [[ADD1:%[0-9]+]]:_(s64) = G_ADD [[ADD]], [[UMULH]]
    ; CHECK-NEXT: $x10 = COPY [[MUL]](s64)
    ; CHECK-NEXT: $x11 = COPY [[ADD1]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10, implicit $x11
    %lo1:_(s64) = COPY $x10
    %hi1:_(s64) = COPY $x11
    %lo2:_(s64) = COPY $x12
    %hi2:_(s64) = COPY $x13
    %x1:_(s128) = G_MERGE_VALUES %lo1(s64), %hi1(s64)
    %x2:_(s128) = G_MERGE_VALUES %lo2(s64), %hi2(s64)
    %y:_(s128) = G_MUL %x1, %x2
    %loy:_(s64), %hiy:_(s64) = G_UNMERGE_VALUES %y(s128)
    $x10 = COPY %loy(s64)
    $x11 = COPY %hiy(s64)
    PseudoRET implicit $x10, implicit $x11

...
---
name:            mul_i192
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: mul_i192
    ; CHECK: %lo1:_(s64) = COPY $x10
    ; CHECK-NEXT: %mid1:_(s64) = COPY $x11
    ; CHECK-NEXT: %hi1:_(s64) = COPY $x12
    ; CHECK-NEXT: %lo2:_(s64) = COPY $x13
    ; CHECK-NEXT: %mid2:_(s64) = COPY $x14
    ; CHECK-NEXT: %hi2:_(s64) = COPY $x15
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL %lo1, %lo2
    ; CHECK-NEXT: [[MUL1:%[0-9]+]]:_(s64) = G_MUL %mid1, %lo2
    ; CHECK-NEXT: [[MUL2:%[0-9]+]]:_(s64) = G_MUL %lo1, %mid2
    ; CHECK-NEXT: [[UMULH:%[0-9]+]]:_(s64) = G_UMULH %lo1, %lo2
    ; CHECK-NEXT: [[ADD:%[0-9]+]]:_(s64) = G_ADD [[MUL1]], [[MUL2]]
    ; CHECK-NEXT: [[ICMP:%[0-9]+]]:_(s64) = G_ICMP intpred(ult), [[ADD]](s64), [[MUL2]]
    ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[ADD]](s64)
    ; CHECK-NEXT: [[ADD1:%[0-9]+]]:_(s64) = G_ADD [[COPY]], [[UMULH]]
    ; CHECK-NEXT: [[ICMP1:%[0-9]+]]:_(s64) = G_ICMP intpred(ult), [[ADD1]](s64), [[UMULH]]
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY [[ADD1]](s64)
    ; CHECK-NEXT: [[ADD2:%[0-9]+]]:_(s64) = G_ADD [[ICMP]], [[ICMP1]]
    ; CHECK-NEXT: [[MUL3:%[0-9]+]]:_(s64) = G_MUL %hi1, %lo2
    ; CHECK-NEXT: [[MUL4:%[0-9]+]]:_(s64) = G_MUL %mid1, %mid2
    ; CHECK-NEXT: [[MUL5:%[0-9]+]]:_(s64) = G_MUL %lo1, %hi2
    ; CHECK-NEXT: [[UMULH1:%[0-9]+]]:_(s64) = G_UMULH %mid1, %lo2
    ; CHECK-NEXT: [[UMULH2:%[0-9]+]]:_(s64) = G_UMULH %lo1, %mid2
    ; CHECK-NEXT: [[ADD3:%[0-9]+]]:_(s64) = G_ADD [[MUL3]], [[MUL4]]
    ; CHECK-NEXT: [[COPY2:%[0-9]+]]:_(s64) = COPY [[ADD3]](s64)
    ; CHECK-NEXT: [[ADD4:%[0-9]+]]:_(s64) = G_ADD [[COPY2]], [[MUL5]]
    ; CHECK-NEXT: [[COPY3:%[0-9]+]]:_(s64) = COPY [[ADD4]](s64)
    ; CHECK-NEXT: [[ADD5:%[0-9]+]]:_(s64) = G_ADD [[COPY3]], [[UMULH1]]
    ; CHECK-NEXT: [[COPY4:%[0-9]+]]:_(s64) = COPY [[ADD5]](s64)
    ; CHECK-NEXT: [[ADD6:%[0-9]+]]:_(s64) = G_ADD [[COPY4]], [[UMULH2]]
    ; CHECK-NEXT: [[COPY5:%[0-9]+]]:_(s64) = COPY [[ADD6]](s64)
    ; CHECK-NEXT: [[ADD7:%[0-9]+]]:_(s64) = G_ADD [[COPY5]], [[ADD2]]
    ; CHECK-NEXT: [[COPY6:%[0-9]+]]:_(s64) = COPY [[ADD7]](s64)
    ; CHECK-NEXT: $x10 = COPY [[MUL]](s64)
    ; CHECK-NEXT: $x11 = COPY [[COPY1]](s64)
    ; CHECK-NEXT: $x12 = COPY [[COPY6]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10, implicit $x11, implicit $x12
    %lo1:_(s64) = COPY $x10
    %mid1:_(s64) = COPY $x11
    %hi1:_(s64) = COPY $x12
    %lo2:_(s64) = COPY $x13
    %mid2:_(s64) = COPY $x14
    %hi2:_(s64) = COPY $x15
    %x1:_(s192) = G_MERGE_VALUES %lo1(s64), %mid1(s64), %hi1(s64)
    %x2:_(s192) = G_MERGE_VALUES %lo2(s64), %mid2(s64), %hi2(s64)
    %y:_(s192) = G_MUL %x1, %x2
    %lo:_(s64), %mid:_(s64), %hi:_(s64) = G_UNMERGE_VALUES %y(s192)
    $x10 = COPY %lo(s64)
    $x11 = COPY %mid(s64)
    $x12 = COPY %hi(s64)
    PseudoRET implicit $x10, implicit $x11, implicit $x12

...
---
name:            smulh_i32
body:             |
  bb.0.entry:
    ; CHECK-LABEL: name: smulh_i32
    ; CHECK: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x11
    ; CHECK-NEXT: [[SEXT_INREG:%[0-9]+]]:_(s64) = G_SEXT_INREG [[COPY]], 32
    ; CHECK-NEXT: [[SEXT_INREG1:%[0-9]+]]:_(s64) = G_SEXT_INREG [[COPY1]], 32
    ; CHECK-NEXT: [[MUL:%[0-9]+]]:_(s64) = G_MUL [[SEXT_INREG]], [[SEXT_INREG1]]
    ; CHECK-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 32
    ; CHECK-NEXT: [[ASHR:%[0-9]+]]:_(s64) = G_ASHR [[MUL]], [[C]](s64)
    ; CHECK-NEXT: $x10 = COPY [[ASHR]](s64)
    ; CHECK-NEXT: PseudoRET implicit $x10
    %0:_(s64) = COPY $x10
    %1:_(s64) = COPY $x11
    %2:_(s32) = G_TRUNC %0(s64)
    %3:_(s32) = G_TRUNC %1(s64)
    %4:_(s32) = G_SMULH %2, %3
    %5:_(s64) = G_ANYEXT %4(s32)
    $x10 = COPY %5(s64)
    PseudoRET implicit $x10

...