llvm/llvm/test/Transforms/JumpTableToSwitch/struct.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

%"struct_ty" = type { [2 x ptr] }

@func_array = constant %"struct_ty" { [2 x ptr] [ptr @func0, ptr @func1] }

define i32 @func0() {
  ret i32 1
}

define i32 @func1() {
  ret i32 2
}

define i32 @function_with_jump_table(i32 %index) {
; CHECK-LABEL: define i32 @function_with_jump_table(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [2 x 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:      i32 1, label [[CALL_1:%.*]]
; 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:       call.1:
; CHECK-NEXT:    [[TMP2:%.*]] = call i32 @func1()
; CHECK-NEXT:    br label [[DOTTAIL]]
; CHECK:       .tail:
; CHECK-NEXT:    [[TMP3:%.*]] = phi i32 [ [[TMP1]], [[CALL_0]] ], [ [[TMP2]], [[CALL_1]] ]
; CHECK-NEXT:    ret i32 [[TMP3]]
;
  %gep = getelementptr inbounds [2 x ptr], ptr @func_array, i32 0, i32 %index
  %func_ptr = load ptr, ptr %gep
  %result = call i32 %func_ptr()
  ret i32 %result
}