llvm/llvm/test/CodeGen/RISCV/GlobalISel/legalizer/legalize-jump-table-brjt-rv64.mir

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=riscv64 -run-pass=legalizer %s -o - \
# RUN: | FileCheck %s

--- |
  define i32 @jt_test(i32 signext %in) {
  entry:
    %0 = sext i32 %in to i64
    switch i64 %0, label %default [
      i64 1, label %bb1
      i64 2, label %bb2
      i64 3, label %bb3
      i64 4, label %bb4
      i64 5, label %bb5
      i64 6, label %bb6
    ]

  bb1:
    ret i32 4

  bb2:
    ret i32 3

  bb3:
    ret i32 2

  bb4:
    ret i32 1

  bb5:
    ret i32 100

  bb6:
    ret i32 200

  default:
    ret i32 1000
  }

...
---
name:            jt_test
tracksRegLiveness: true
jumpTable:
  kind:            custom32
  entries:
    - id:              0
      blocks:          [ '%bb.2', '%bb.3', '%bb.4', '%bb.5', '%bb.6', '%bb.7' ]
body:             |
  ; CHECK-LABEL: name: jt_test
  ; CHECK: bb.0.entry:
  ; CHECK-NEXT:   successors: %bb.8(0x40000000), %bb.1(0x40000000)
  ; CHECK-NEXT:   liveins: $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:_(s64) = COPY $x10
  ; CHECK-NEXT:   [[ASSERT_SEXT:%[0-9]+]]:_(s64) = G_ASSERT_SEXT [[COPY]], 32
  ; CHECK-NEXT:   [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 5
  ; CHECK-NEXT:   [[C1:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
  ; CHECK-NEXT:   [[SUB:%[0-9]+]]:_(s64) = G_SUB [[ASSERT_SEXT]], [[C1]]
  ; CHECK-NEXT:   [[ICMP:%[0-9]+]]:_(s64) = G_ICMP intpred(ugt), [[SUB]](s64), [[C]]
  ; CHECK-NEXT:   G_BRCOND [[ICMP]](s64), %bb.8
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.1.entry:
  ; CHECK-NEXT:   successors: %bb.2(0x15555555), %bb.3(0x15555555), %bb.4(0x15555555), %bb.5(0x15555555), %bb.6(0x15555555), %bb.7(0x15555555)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT:   [[JUMP_TABLE:%[0-9]+]]:_(p0) = G_JUMP_TABLE %jump-table.0
  ; CHECK-NEXT:   G_BRJT [[JUMP_TABLE]](p0), %jump-table.0, [[SUB]](s64)
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2.bb1:
  ; CHECK-NEXT:   [[C2:%[0-9]+]]:_(s64) = G_CONSTANT i64 4
  ; CHECK-NEXT:   $x10 = COPY [[C2]](s64)
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3.bb2:
  ; CHECK-NEXT:   [[C3:%[0-9]+]]:_(s64) = G_CONSTANT i64 3
  ; CHECK-NEXT:   $x10 = COPY [[C3]](s64)
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.4.bb3:
  ; CHECK-NEXT:   [[C4:%[0-9]+]]:_(s64) = G_CONSTANT i64 2
  ; CHECK-NEXT:   $x10 = COPY [[C4]](s64)
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.5.bb4:
  ; CHECK-NEXT:   [[C5:%[0-9]+]]:_(s64) = G_CONSTANT i64 1
  ; CHECK-NEXT:   $x10 = COPY [[C5]](s64)
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.6.bb5:
  ; CHECK-NEXT:   [[C6:%[0-9]+]]:_(s64) = G_CONSTANT i64 100
  ; CHECK-NEXT:   $x10 = COPY [[C6]](s64)
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.7.bb6:
  ; CHECK-NEXT:   [[C7:%[0-9]+]]:_(s64) = G_CONSTANT i64 200
  ; CHECK-NEXT:   $x10 = COPY [[C7]](s64)
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.8.default:
  ; CHECK-NEXT:   [[C8:%[0-9]+]]:_(s64) = G_CONSTANT i64 1000
  ; CHECK-NEXT:   $x10 = COPY [[C8]](s64)
  ; CHECK-NEXT:   PseudoRET implicit $x10
  bb.1.entry:
    successors: %bb.8, %bb.9
    liveins: $x10

    %1:_(s64) = COPY $x10
    %2:_(s64) = G_ASSERT_SEXT %1, 32
    %0:_(s32) = G_TRUNC %2(s64)
    %7:_(s64) = G_CONSTANT i64 5
    %3:_(s64) = G_SEXT %0(s32)
    %4:_(s64) = G_CONSTANT i64 1
    %5:_(s64) = G_SUB %3, %4
    %9:_(s1) = G_ICMP intpred(ugt), %5(s64), %7
    G_BRCOND %9(s1), %bb.8

  bb.9.entry:
    successors: %bb.2, %bb.3, %bb.4, %bb.5, %bb.6, %bb.7

    %10:_(p0) = G_JUMP_TABLE %jump-table.0
    G_BRJT %10(p0), %jump-table.0, %5(s64)

  bb.2.bb1:
    %22:_(s64) = G_CONSTANT i64 4
    $x10 = COPY %22(s64)
    PseudoRET implicit $x10

  bb.3.bb2:
    %20:_(s64) = G_CONSTANT i64 3
    $x10 = COPY %20(s64)
    PseudoRET implicit $x10

  bb.4.bb3:
    %18:_(s64) = G_CONSTANT i64 2
    $x10 = COPY %18(s64)
    PseudoRET implicit $x10

  bb.5.bb4:
    %16:_(s64) = G_CONSTANT i64 1
    $x10 = COPY %16(s64)
    PseudoRET implicit $x10

  bb.6.bb5:
    %14:_(s64) = G_CONSTANT i64 100
    $x10 = COPY %14(s64)
    PseudoRET implicit $x10

  bb.7.bb6:
    %12:_(s64) = G_CONSTANT i64 200
    $x10 = COPY %12(s64)
    PseudoRET implicit $x10

  bb.8.default:
    %24:_(s64) = G_CONSTANT i64 1000
    $x10 = COPY %24(s64)
    PseudoRET implicit $x10

...