1919// A lower bounds check is left behind in the entry block
2020
2121// 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
2626// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A29_sum_iterate_to_count_wo_trapySis4SpanVySiGF'
2727
2828// 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 {
4141// A lower bounds check is left behind in the entry block
4242
4343// 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
4848// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_sum_iterate_to_count_with_trapySis4SpanVySiGF'
4949
5050public 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 {
6161// A lower bounds check is left behind in the entry block
6262
6363// 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
6868// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_sum_iterate_to_unknown_wo_trapySis4SpanVySiG_SitF'
6969
7070// 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
7878}
7979
8080// 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
8184
8285// 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
8790// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A33_sum_iterate_to_unknown_with_trapySis4SpanVySiG_SitF'
8891public func span_sum_iterate_to_unknown_with_trap( _ v: Span < Int > , _ n: Int ) -> Int {
8992 var sum = 0
@@ -98,10 +101,10 @@ public func span_sum_iterate_to_unknown_with_trap(_ v: Span<Int>, _ n: Int) -> I
98101// LLVM removes the upper bounds check from the loop and then vectorizes
99102
100103// 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
105108// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count1_wo_trapySis4SpanVySiG_SitF'
106109
107110// 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
116119}
117120
118121// Bounds check should be eliminated
122+ // SIL removes lower bounds check from the loop
123+ // LLVM does not eliminate redundant bounds check
119124
120125// 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
125130// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count1_with_trapySis4SpanVySiG_SitF'
126131public func span_sum_iterate_to_deducible_count1_with_trap( _ v: Span < Int > , _ n: Int ) -> Int {
127132 var sum = 0
@@ -133,12 +138,14 @@ public func span_sum_iterate_to_deducible_count1_with_trap(_ v: Span<Int>, _ n:
133138}
134139
135140// Bounds check should be eliminated
141+ // SIL removes lower bounds check from the loop
142+ // LLVM removes upper bounds check and vectorizes the loop
136143
137144// 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
142149// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count2_wo_trapySis4SpanVySiG_SitF'
143150
144151// 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
153160}
154161
155162// Bounds check should be eliminated
163+ // SIL removes lower bounds check from the loop
164+ // LLVM does not eliminate redundant bounds check
156165
157166// 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
162171// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count2_with_trapySis4SpanVySiG_SitF'
163172public func span_sum_iterate_to_deducible_count2_with_trap( _ v: Span < Int > , _ n: Int ) -> Int {
164173 var sum = 0
@@ -170,12 +179,14 @@ public func span_sum_iterate_to_deducible_count2_with_trap(_ v: Span<Int>, _ n:
170179}
171180
172181// Bounds check should be eliminated
182+ // SIL removes lower bounds check from the loop
183+ // LLVM removes upper bounds check and vectorizes the loop
173184
174185// 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
179190// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A29_iterate_over_indices_wo_trapySis4SpanVySiGF'
180191
181192// 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 {
189200}
190201
191202// Bounds check should be eliminated
203+ // SIL removes lower bounds check from the loop
204+ // LLVM does not eliminate redundant bounds check
192205
193206// 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
198211// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_iterate_over_indices_with_trapySis4SpanVySiGF'
199212public func span_iterate_over_indices_with_trap( _ v: Span < Int > ) -> Int {
200213 var sum = 0
@@ -207,10 +220,8 @@ public func span_iterate_over_indices_with_trap(_ v: Span<Int>) -> Int {
207220// Eliminate duplicate bounds check
208221
209222// 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"
214225// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A17_element_equalityySbs4SpanVySiG_SitF'
215226
216227public 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 {
220231// Eliminate duplicate bounds check
221232
222233// 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"
227236// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A12_element_sumySis4SpanVySiG_SitF'
228237
229238public 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 {
233242// Bounds check should be eliminated
234243
235244// 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
240249// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A7_searchySiSgs4SpanVyxG_xtSQRzlF'
241250public func span_search< T : Equatable > ( _ v: Span < T > , _ elem: T ) -> Int ? {
242251 for i in v. indices {
@@ -250,10 +259,10 @@ public func span_search<T : Equatable>(_ v: Span<T>, _ elem: T) -> Int? {
250259// Bounds check should be eliminated
251260
252261// 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
257266// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A11_search_splySiSgs4SpanVySiG_SitF'
258267public func span_search_spl( _ v: Span < Int > , _ elem: Int ) -> Int ? {
259268 for i in v. indices {
@@ -267,9 +276,9 @@ public func span_search_spl(_ v: Span<Int>, _ elem: Int) -> Int? {
267276// Bounds check should be eliminated
268277
269278// 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
273282// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A18_binary_search_splySiSgs4SpanVySiG_SitF'
274283public func span_binary_search_spl( _ v: Span < Int > , _ elem: Int ) -> Int ? {
275284 var low = 0 , high = v. count - 1
0 commit comments