aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/Transforms/JumpTableToSwitch/skip.ll
blob: 4504423a015236bf94093f4a78279b24ccc692bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
; 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_array0 = constant [2 x ptr] [ptr @func0, ptr @declared_only_func1]

define i32 @func0() {
  ret i32 1
}

declare i32 @declared_only_func1()

define i32 @function_with_jump_table_with_a_declared_only_func(i32 %index) {
; CHECK-LABEL: define i32 @function_with_jump_table_with_a_declared_only_func(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array0, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
; CHECK-NEXT:    [[RESULT:%.*]] = call i32 [[FUNC_PTR]]()
; CHECK-NEXT:    ret i32 [[RESULT]]
;
  %gep = getelementptr inbounds [2 x ptr], ptr @func_array0, i32 0, i32 %index
  %func_ptr = load ptr, ptr %gep, align 8
  %result = call i32 %func_ptr()
  ret i32 %result
}

declare i32 @__gxx_personality_v0(...)

define i32 @function_with_jump_table_invoke(i32 %index) personality ptr @__gxx_personality_v0 {
; CHECK-LABEL: define i32 @function_with_jump_table_invoke(
; CHECK-SAME: i32 [[INDEX:%.*]]) personality ptr @__gxx_personality_v0 {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [2 x ptr], ptr @func_array0, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
; CHECK-NEXT:    [[RESULT:%.*]] = invoke i32 [[FUNC_PTR]]()
; CHECK-NEXT:            to label [[NORMAL:%.*]] unwind label [[EXCEPTIONAL:%.*]]
; CHECK:       normal:
; CHECK-NEXT:    ret i32 [[RESULT]]
; CHECK:       exceptional:
; CHECK-NEXT:    [[LANDING_PAD:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT:            catch ptr null
; CHECK-NEXT:    resume { ptr, i32 } [[LANDING_PAD]]
;
  %gep = getelementptr inbounds [2 x ptr], ptr @func_array0, i32 0, i32 %index
  %func_ptr = load ptr, ptr %gep, align 8
  %result = invoke i32 %func_ptr() to label %normal unwind label %exceptional
normal:
  ret i32 %result
exceptional:
  %landing_pad = landingpad { ptr, i32 } catch ptr null
  resume { ptr, i32 } %landing_pad
}

@func_array1 = constant [1 x ptr] [ptr @func2]

define i32 @func2(i32 %arg) {
  ret i32 %arg
}

define i32 @function_with_jump_table_musttail_call(i32 %index) {
; CHECK-LABEL: define i32 @function_with_jump_table_musttail_call(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [1 x ptr], ptr @func_array1, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
; CHECK-NEXT:    [[RESULT:%.*]] = musttail call i32 [[FUNC_PTR]](i32 [[INDEX]])
; CHECK-NEXT:    ret i32 [[RESULT]]
;
  %gep = getelementptr inbounds [1 x ptr], ptr @func_array1, i32 0, i32 %index
  %func_ptr = load ptr, ptr %gep, align 8
  %result = musttail call i32 %func_ptr(i32 %index)
  ret i32 %result
}

define i32 @function_with_jump_table_and_volatile_load(i32 %index) {
; CHECK-LABEL: define i32 @function_with_jump_table_and_volatile_load(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [1 x ptr], ptr @func_array1, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load volatile ptr, ptr [[GEP]], align 8
; CHECK-NEXT:    [[RESULT:%.*]] = call i32 [[FUNC_PTR]](i32 [[INDEX]])
; CHECK-NEXT:    ret i32 [[RESULT]]
;
  %gep = getelementptr inbounds [1 x ptr], ptr @func_array1, i32 0, i32 %index
  %func_ptr = load volatile ptr, ptr %gep, align 8
  %result = call i32 %func_ptr(i32 %index)
  ret i32 %result
}

define i32 @function_with_jump_table_and_atomic_load(i32 %index) {
; CHECK-LABEL: define i32 @function_with_jump_table_and_atomic_load(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [1 x ptr], ptr @func_array1, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load atomic ptr, ptr [[GEP]] monotonic, align 8
; CHECK-NEXT:    [[RESULT:%.*]] = call i32 [[FUNC_PTR]](i32 [[INDEX]])
; CHECK-NEXT:    ret i32 [[RESULT]]
;
  %gep = getelementptr inbounds [1 x ptr], ptr @func_array1, i32 0, i32 %index
  %func_ptr = load atomic ptr, ptr %gep monotonic, align 8
  %result = call i32 %func_ptr(i32 %index)
  ret i32 %result
}

@func_array2 = global [1 x ptr] [ptr @func2]

define i32 @function_with_nonconstant_jump_table(i32 %index) {
; CHECK-LABEL: define i32 @function_with_nonconstant_jump_table(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [1 x ptr], ptr @func_array2, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
; CHECK-NEXT:    [[RESULT:%.*]] = call i32 [[FUNC_PTR]](i32 [[INDEX]])
; CHECK-NEXT:    ret i32 [[RESULT]]
;
  %gep = getelementptr inbounds [1 x ptr], ptr @func_array2, i32 0, i32 %index
  %func_ptr = load ptr, ptr %gep, align 8
  %result = call i32 %func_ptr(i32 %index)
  ret i32 %result
}

@func_array3 = weak constant [1 x ptr] [ptr @func2]

define i32 @function_with_constant_weak_jump_table(i32 %index) {
; CHECK-LABEL: define i32 @function_with_constant_weak_jump_table(
; CHECK-SAME: i32 [[INDEX:%.*]]) {
; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [1 x ptr], ptr @func_array3, i32 0, i32 [[INDEX]]
; CHECK-NEXT:    [[FUNC_PTR:%.*]] = load ptr, ptr [[GEP]], align 8
; CHECK-NEXT:    [[RESULT:%.*]] = call i32 [[FUNC_PTR]](i32 [[INDEX]])
; CHECK-NEXT:    ret i32 [[RESULT]]
;
  %gep = getelementptr inbounds [1 x ptr], ptr @func_array3, i32 0, i32 %index
  %func_ptr = load ptr, ptr %gep, align 8
  %result = call i32 %func_ptr(i32 %index)
  ret i32 %result
}