19
19
// A lower bounds check is left behind in the entry block
20
20
21
21
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A29_sum_iterate_to_count_wo_trapySis4SpanVySiGF :
22
- // CHECK: bb3
23
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
24
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
25
- // CHECK: cond_br
22
+ // CHECK-SIL : bb3
23
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
24
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
25
+ // CHECK-SIL : cond_br
26
26
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A29_sum_iterate_to_count_wo_trapySis4SpanVySiGF'
27
27
28
28
// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A29_sum_iterate_to_count_wo_trapySis4SpanVySiGF"
@@ -41,10 +41,10 @@ public func span_sum_iterate_to_count_wo_trap(_ v: Span<Int>) -> Int {
41
41
// A lower bounds check is left behind in the entry block
42
42
43
43
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A31_sum_iterate_to_count_with_trapySis4SpanVySiGF :
44
- // CHECK: bb3
45
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
46
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
47
- // CHECK: cond_br
44
+ // CHECK-SIL : bb3
45
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
46
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
47
+ // CHECK-SIL : cond_br
48
48
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_sum_iterate_to_count_with_trapySis4SpanVySiGF'
49
49
50
50
public func span_sum_iterate_to_count_with_trap( _ v: Span < Int > ) -> Int {
@@ -61,10 +61,10 @@ public func span_sum_iterate_to_count_with_trap(_ v: Span<Int>) -> Int {
61
61
// A lower bounds check is left behind in the entry block
62
62
63
63
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A31_sum_iterate_to_unknown_wo_trapySis4SpanVySiG_SitF :
64
- // CHECK: bb3
65
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
66
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
67
- // CHECK: cond_br
64
+ // CHECK-SIL : bb3
65
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
66
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
67
+ // CHECK-SIL : cond_br
68
68
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_sum_iterate_to_unknown_wo_trapySis4SpanVySiG_SitF'
69
69
70
70
// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A31_sum_iterate_to_unknown_wo_trapySis4SpanVySiG_SitF"
@@ -78,12 +78,15 @@ public func span_sum_iterate_to_unknown_wo_trap(_ v: Span<Int>, _ n: Int) -> Int
78
78
}
79
79
80
80
// Bounds check should be hoisted
81
+ // SIL removes lower bounds check from the loop
82
+ // LLVM removes the upper bounds check from the loop
83
+ // A lower bounds check is left behind in the entry block
81
84
82
85
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A33_sum_iterate_to_unknown_with_trapySis4SpanVySiG_SitF :
83
- // CHECK: bb3
84
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
85
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
86
- // CHECK: cond_br
86
+ // CHECK-SIL : bb3
87
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
88
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
89
+ // CHECK-SIL : cond_br
87
90
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A33_sum_iterate_to_unknown_with_trapySis4SpanVySiG_SitF'
88
91
public func span_sum_iterate_to_unknown_with_trap( _ v: Span < Int > , _ n: Int ) -> Int {
89
92
var sum = 0
@@ -98,10 +101,10 @@ public func span_sum_iterate_to_unknown_with_trap(_ v: Span<Int>, _ n: Int) -> I
98
101
// LLVM removes the upper bounds check from the loop and then vectorizes
99
102
100
103
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count1_wo_trapySis4SpanVySiG_SitF :
101
- // CHECK: bb3
102
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
103
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
104
- // CHECK: cond_br
104
+ // CHECK-SIL : bb3
105
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
106
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
107
+ // CHECK-SIL : cond_br
105
108
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count1_wo_trapySis4SpanVySiG_SitF'
106
109
107
110
// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count1_wo_trapySis4SpanVySiG_SitF"
@@ -116,12 +119,14 @@ public func span_sum_iterate_to_deducible_count1_wo_trap(_ v: Span<Int>, _ n: In
116
119
}
117
120
118
121
// Bounds check should be eliminated
122
+ // SIL removes lower bounds check from the loop
123
+ // LLVM does not eliminate redundant bounds check
119
124
120
125
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count1_with_trapySis4SpanVySiG_SitF :
121
- // CHECK: bb3
122
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
123
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
124
- // CHECK: cond_br
126
+ // CHECK-SIL : bb3
127
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
128
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
129
+ // CHECK-SIL : cond_br
125
130
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count1_with_trapySis4SpanVySiG_SitF'
126
131
public func span_sum_iterate_to_deducible_count1_with_trap( _ v: Span < Int > , _ n: Int ) -> Int {
127
132
var sum = 0
@@ -133,12 +138,14 @@ public func span_sum_iterate_to_deducible_count1_with_trap(_ v: Span<Int>, _ n:
133
138
}
134
139
135
140
// Bounds check should be eliminated
141
+ // SIL removes lower bounds check from the loop
142
+ // LLVM removes upper bounds check and vectorizes the loop
136
143
137
144
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count2_wo_trapySis4SpanVySiG_SitF :
138
- // CHECK: bb3
139
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
140
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
141
- // CHECK: cond_br
145
+ // CHECK-SIL : bb3
146
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
147
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
148
+ // CHECK-SIL : cond_br
142
149
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count2_wo_trapySis4SpanVySiG_SitF'
143
150
144
151
// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count2_wo_trapySis4SpanVySiG_SitF"
@@ -153,12 +160,14 @@ public func span_sum_iterate_to_deducible_count2_wo_trap(_ v: Span<Int>, _ n: In
153
160
}
154
161
155
162
// Bounds check should be eliminated
163
+ // SIL removes lower bounds check from the loop
164
+ // LLVM does not eliminate redundant bounds check
156
165
157
166
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count2_with_trapySis4SpanVySiG_SitF :
158
- // CHECK: bb3
159
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
160
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
161
- // CHECK: cond_br
167
+ // CHECK-SIL : bb3
168
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
169
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
170
+ // CHECK-SIL : cond_br
162
171
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count2_with_trapySis4SpanVySiG_SitF'
163
172
public func span_sum_iterate_to_deducible_count2_with_trap( _ v: Span < Int > , _ n: Int ) -> Int {
164
173
var sum = 0
@@ -170,12 +179,14 @@ public func span_sum_iterate_to_deducible_count2_with_trap(_ v: Span<Int>, _ n:
170
179
}
171
180
172
181
// Bounds check should be eliminated
182
+ // SIL removes lower bounds check from the loop
183
+ // LLVM removes upper bounds check and vectorizes the loop
173
184
174
185
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A29_iterate_over_indices_wo_trapySis4SpanVySiGF :
175
- // CHECK: bb3
176
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
177
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
178
- // CHECK: cond_br
186
+ // CHECK-SIL : bb3
187
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
188
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
189
+ // CHECK-SIL : cond_br
179
190
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A29_iterate_over_indices_wo_trapySis4SpanVySiGF'
180
191
181
192
// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A29_iterate_over_indices_wo_trapySis4SpanVySiGF"
@@ -189,12 +200,14 @@ public func span_iterate_over_indices_wo_trap(_ v: Span<Int>) -> Int {
189
200
}
190
201
191
202
// Bounds check should be eliminated
203
+ // SIL removes lower bounds check from the loop
204
+ // LLVM does not eliminate redundant bounds check
192
205
193
206
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A31_iterate_over_indices_with_trapySis4SpanVySiGF :
194
- // CHECK: bb3
195
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
196
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
197
- // CHECK: cond_br
207
+ // CHECK-SIL : bb3
208
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
209
+ // CHECK-SIL- NOT: cond_fail {{.*}}, "Index out of bounds"
210
+ // CHECK-SIL : cond_br
198
211
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_iterate_over_indices_with_trapySis4SpanVySiGF'
199
212
public func span_iterate_over_indices_with_trap( _ v: Span < Int > ) -> Int {
200
213
var sum = 0
@@ -207,10 +220,8 @@ public func span_iterate_over_indices_with_trap(_ v: Span<Int>) -> Int {
207
220
// Eliminate duplicate bounds check
208
221
209
222
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A17_element_equalityySbs4SpanVySiG_SitF :
210
- // CHECK: bb3
211
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
212
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
213
- // CHECK: cond_br
223
+ // CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
224
+ // CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
214
225
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A17_element_equalityySbs4SpanVySiG_SitF'
215
226
216
227
public func span_element_equality( _ v: Span < Int > , _ i: Int ) -> Bool {
@@ -220,10 +231,8 @@ public func span_element_equality(_ v: Span<Int>, _ i: Int) -> Bool {
220
231
// Eliminate duplicate bounds check
221
232
222
233
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A12_element_sumySis4SpanVySiG_SitF :
223
- // CHECK: bb3
224
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
225
- // CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
226
- // CHECK: cond_br
234
+ // CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
235
+ // CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
227
236
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A12_element_sumySis4SpanVySiG_SitF'
228
237
229
238
public func span_element_sum( _ v: Span < Int > , _ i: Int ) -> Int {
@@ -233,10 +242,10 @@ public func span_element_sum(_ v: Span<Int>, _ i: Int) -> Int {
233
242
// Bounds check should be eliminated
234
243
235
244
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A7_searchySiSgs4SpanVyxG_xtSQRzlF :
236
- // CHECK: bb3
237
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
238
- // CHECK-NOT : cond_fail {{.*}}, "Index out of bounds"
239
- // CHECK: cond_br
245
+ // CHECK-SIL : bb3:
246
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
247
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
248
+ // CHECK-SIL : cond_br
240
249
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A7_searchySiSgs4SpanVyxG_xtSQRzlF'
241
250
public func span_search< T : Equatable > ( _ v: Span < T > , _ elem: T ) -> Int ? {
242
251
for i in v. indices {
@@ -250,10 +259,10 @@ public func span_search<T : Equatable>(_ v: Span<T>, _ elem: T) -> Int? {
250
259
// Bounds check should be eliminated
251
260
252
261
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A11_search_splySiSgs4SpanVySiG_SitF :
253
- // CHECK: bb3
254
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
255
- // CHECK-NOT : cond_fail {{.*}}, "Index out of bounds"
256
- // CHECK: cond_br
262
+ // CHECK-SIL : bb3:
263
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
264
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
265
+ // CHECK-SIL : cond_br
257
266
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A11_search_splySiSgs4SpanVySiG_SitF'
258
267
public func span_search_spl( _ v: Span < Int > , _ elem: Int ) -> Int ? {
259
268
for i in v. indices {
@@ -267,9 +276,9 @@ public func span_search_spl(_ v: Span<Int>, _ elem: Int) -> Int? {
267
276
// Bounds check should be eliminated
268
277
269
278
// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A18_binary_search_splySiSgs4SpanVySiG_SitF :
270
- // CHECK: bb2
271
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
272
- // CHECK: cond_br
279
+ // CHECK-SIL : bb2
280
+ // CHECK-SIL : cond_fail {{.*}}, "Index out of bounds"
281
+ // CHECK-SIL : cond_br
273
282
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A18_binary_search_splySiSgs4SpanVySiG_SitF'
274
283
public func span_binary_search_spl( _ v: Span < Int > , _ elem: Int ) -> Int ? {
275
284
var low = 0 , high = v. count - 1
0 commit comments