llvm/llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/jump-table-brjt-pic-rv64.mir

# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=riscv64 -run-pass=instruction-select %s -o - \
# RUN:   -relocation-model=pic | 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:                                              ; preds = %entry
    ret i32 4

  bb2:                                              ; preds = %entry
    ret i32 3

  bb3:                                              ; preds = %entry
    ret i32 2

  bb4:                                              ; preds = %entry
    ret i32 1

  bb5:                                              ; preds = %entry
    ret i32 100

  bb6:                                              ; preds = %entry
    ret i32 200

  default:                                          ; preds = %entry
    ret i32 1000
  }

...
---
name:            jt_test
legalized:       true
regBankSelected: true
tracksRegLiveness: true
jumpTable:
  kind:            label-difference32
  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]+]]:gpr = COPY $x10
  ; CHECK-NEXT:   [[ADDI:%[0-9]+]]:gpr = ADDI $x0, 5
  ; CHECK-NEXT:   [[ADDIW:%[0-9]+]]:gpr = ADDIW [[COPY]], 0
  ; CHECK-NEXT:   [[ADDI1:%[0-9]+]]:gpr = ADDI [[ADDIW]], -1
  ; CHECK-NEXT:   BLTU [[ADDI]], [[ADDI1]], %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:   [[PseudoLLA:%[0-9]+]]:gpr = PseudoLLA %jump-table.0
  ; CHECK-NEXT:   [[SLLI:%[0-9]+]]:gpr = SLLI [[ADDI1]], 2
  ; CHECK-NEXT:   [[ADD:%[0-9]+]]:gpr = ADD [[PseudoLLA]], [[SLLI]]
  ; CHECK-NEXT:   [[LW:%[0-9]+]]:gpr = LW [[ADD]], 0 :: (load (s32) from jump-table)
  ; CHECK-NEXT:   [[ADD1:%[0-9]+]]:gprjalr = ADD [[LW]], [[PseudoLLA]]
  ; CHECK-NEXT:   PseudoBRIND [[ADD1]], 0
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.2.bb1:
  ; CHECK-NEXT:   [[ADDI2:%[0-9]+]]:gpr = ADDI $x0, 4
  ; CHECK-NEXT:   $x10 = COPY [[ADDI2]]
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.3.bb2:
  ; CHECK-NEXT:   [[ADDI3:%[0-9]+]]:gpr = ADDI $x0, 3
  ; CHECK-NEXT:   $x10 = COPY [[ADDI3]]
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.4.bb3:
  ; CHECK-NEXT:   [[ADDI4:%[0-9]+]]:gpr = ADDI $x0, 2
  ; CHECK-NEXT:   $x10 = COPY [[ADDI4]]
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.5.bb4:
  ; CHECK-NEXT:   [[ADDI5:%[0-9]+]]:gpr = ADDI $x0, 1
  ; CHECK-NEXT:   $x10 = COPY [[ADDI5]]
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.6.bb5:
  ; CHECK-NEXT:   [[ADDI6:%[0-9]+]]:gpr = ADDI $x0, 100
  ; CHECK-NEXT:   $x10 = COPY [[ADDI6]]
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.7.bb6:
  ; CHECK-NEXT:   [[ADDI7:%[0-9]+]]:gpr = ADDI $x0, 200
  ; CHECK-NEXT:   $x10 = COPY [[ADDI7]]
  ; CHECK-NEXT:   PseudoRET implicit $x10
  ; CHECK-NEXT: {{  $}}
  ; CHECK-NEXT: bb.8.default:
  ; CHECK-NEXT:   [[ADDI8:%[0-9]+]]:gpr = ADDI $x0, 1000
  ; CHECK-NEXT:   $x10 = COPY [[ADDI8]]
  ; CHECK-NEXT:   PseudoRET implicit $x10
  bb.1.entry:
    successors: %bb.8, %bb.9
    liveins: $x10

    %1:gprb(s64) = COPY $x10
    %2:gprb(s64) = G_ASSERT_SEXT %1, 32
    %7:gprb(s64) = G_CONSTANT i64 5
    %3:gprb(s64) = G_SEXT_INREG %2, 32
    %4:gprb(s64) = G_CONSTANT i64 1
    %5:gprb(s64) = G_SUB %3, %4
    %26:gprb(s64) = G_ICMP intpred(ugt), %5(s64), %7
    G_BRCOND %26(s64), %bb.8

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

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

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

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

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

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

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

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

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

...