llvm/llvm/test/Transforms/JumpTableToSwitch/stride.ll

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes=jump-table-to-switch -verify-dom-info -S | FileCheck %s

@func_array = constant [2 x ptr] [ptr @func0, ptr @func1]

define i32 @func0() {
  ret i32 1
}

define i32 @func1() {
  ret i32 2
}

define i32 @check_stride(i32 %index) {
; CHECK-LABEL: define i32 @check_stride(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [2 x { ptr, ptr }], ptr @func_array, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
; CHECK-NEXT:    switch i32 [[INDEX]], label [[DEFAULT_SWITCH_CASE_UNREACHABLE:%.*]] [
; CHECK-NEXT:      i32 0, label [[CALL_0:%.*]]
; CHECK-NEXT:    ]
; CHECK:       default.switch.case.unreachable:
; CHECK-NEXT:    unreachable
; CHECK:       call.0:
; CHECK-NEXT:    [[TMP1:%.*]] = call i32 @func0()
; CHECK-NEXT:    br label [[DOTTAIL:%.*]]
; CHECK:       .tail:
; CHECK-NEXT:    [[TMP2:%.*]] = phi i32 [ [[TMP1]], [[CALL_0]] ]
; CHECK-NEXT:    ret i32 [[TMP2]]
;
  %gep = getelementptr inbounds [2 x { ptr, ptr }], ptr @func_array, i32 0, i32 %index
  %func_ptr = load ptr, ptr %gep
  %result = call i32 %func_ptr()
  ret i32 %result
}