fold-not-thread.ll
4.76 KB
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
; RUN: opt -jump-threading -S -verify < %s | FileCheck %s
declare i32 @f1()
declare i32 @f2()
declare void @f3()
declare void @f4(i32)
; Make sure we update the phi node properly.
;
; CHECK-LABEL: define void @test_br_folding_not_threading_update_phi(
; CHECK: br label %L1
; Make sure we update the phi node properly here, i.e. we only have 2 predecessors, entry and L0
; CHECK: %res.0 = phi i32 [ 0, %L0 ], [ 1, %entry ]
define void @test_br_folding_not_threading_update_phi(i32 %val) nounwind {
entry:
%cmp = icmp eq i32 %val, 32
br i1 %cmp, label %L0, label %L1
L0:
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
switch i32 %val, label %L2 [
i32 0, label %L1
i32 32, label %L1
]
L1:
%res.0 = phi i32 [ 0, %L0 ], [ 0, %L0 ], [1, %entry]
call void @f4(i32 %res.0)
ret void
L2:
call void @f3()
ret void
}
; Make sure we can fold this branch ... We will not be able to thread it as
; L0 is too big to duplicate. L2 is the unreachable block here.
;
; CHECK-LABEL: @test_br_folding_not_threading(
; CHECK: L1:
; CHECK: call i32 @f2()
; CHECK: call void @f3()
; CHECK-NEXT: ret void
; CHECK-NOT: br
; CHECK: L3:
define void @test_br_folding_not_threading(i1 %cond) nounwind {
entry:
br i1 %cond, label %L0, label %L3
L0:
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
br i1 %cond, label %L1, label %L2
L1:
call void @f3()
ret void
L2:
call void @f3()
ret void
L3:
call void @f3()
ret void
}
; Make sure we can fold this branch ... We will not be able to thread it as
; L0 is too big to duplicate. L2 is the unreachable block here.
; With more than 1 predecessors.
;
; CHECK-LABEL: @test_br_folding_not_threading_multiple_preds(
; CHECK: L1:
; CHECK: call i32 @f2()
; CHECK: call void @f3()
; CHECK-NEXT: ret void
; CHECK-NOT: br
; CHECK: L3:
define void @test_br_folding_not_threading_multiple_preds(i1 %condx, i1 %cond) nounwind {
entry:
br i1 %condx, label %X0, label %X1
X0:
br i1 %cond, label %L0, label %L3
X1:
br i1 %cond, label %L0, label %L3
L0:
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
br i1 %cond, label %L1, label %L2
L1:
call void @f3()
ret void
L2:
call void @f3()
ret void
L3:
call void @f3()
ret void
}
; Make sure we can do the RAUW for %add...
;
; CHECK-LABEL: @rauw_if_possible(
; CHECK: call void @f4(i32 96)
define void @rauw_if_possible(i32 %value) nounwind {
entry:
%cmp = icmp eq i32 %value, 32
br i1 %cmp, label %L0, label %L3
L0:
call i32 @f2()
call i32 @f2()
%add = add i32 %value, 64
switch i32 %add, label %L3 [
i32 32, label %L1
i32 96, label %L2
]
L1:
call void @f3()
ret void
L2:
call void @f4(i32 %add)
ret void
L3:
call void @f3()
ret void
}
; Make sure we can NOT do the RAUW for %add...
;
; CHECK-LABEL: @rauw_if_possible2(
; CHECK: call void @f4(i32 %add)
define void @rauw_if_possible2(i32 %value) nounwind {
entry:
%cmp = icmp eq i32 %value, 32
%add = add i32 %value, 64
br i1 %cmp, label %L0, label %L2
L0:
call i32 @f2()
call i32 @f2()
switch i32 %add, label %L3 [
i32 32, label %L1
i32 96, label %L2
]
L1:
call void @f3()
ret void
L2:
call void @f4(i32 %add)
ret void
L3:
call void @f3()
ret void
}
; Make sure we can fold this branch ... We will not be able to thread it as
; L0 is too big to duplicate.
; We do not attempt to rewrite the indirectbr target here, but we still take
; its target after L0 into account and that enables us to fold.
;
; L2 is the unreachable block here.
;
; CHECK-LABEL: @test_br_folding_not_threading_indirect_branch(
; CHECK: L1:
; CHECK: call i32 @f2()
; CHECK: call void @f3()
; CHECK-NEXT: ret void
; CHECK-NOT: br
; CHECK: L3:
define void @test_br_folding_not_threading_indirect_branch(i1 %condx, i1 %cond) nounwind {
entry:
br i1 %condx, label %X0, label %X1
X0:
br i1 %cond, label %L0, label %L3
X1:
br i1 %cond, label %XX1, label %L3
XX1:
indirectbr i8* blockaddress(@test_br_folding_not_threading_indirect_branch, %L0), [label %L0]
L0:
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
call i32 @f2()
br i1 %cond, label %L1, label %L2
L1:
call void @f3()
ret void
L2:
call void @f3()
ret void
L3:
call void @f3()
ret void
}