Skip to content

Commit e6c772b

Browse files
authored
Merge pull request #79275 from meg-gupta/boundstestsupdate2
[Test] Enable test for all platforms and update check lines
2 parents f60394d + 0a860a1 commit e6c772b

File tree

2 files changed

+81
-69
lines changed

2 files changed

+81
-69
lines changed

test/SILOptimizer/mutable_span_bounds_check_tests.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010

1111
// REQUIRES: swift_stdlib_no_asserts, optimized_stdlib
1212

13-
// In Inputs/SpanExtras.swift we have @available(macOS 9999, *):
14-
// REQUIRES: OS=macosx
15-
1613
import SpanExtras
1714

1815
// Bounds check should be eliminated
19-
// SIL does not optimize this
20-
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop
16+
// SIL removes lower bounds check
17+
// LLVM removes upper bounds check and vectorizes the loop
2118

2219
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF :
2320
// CHECK-SIL: bb3({{.*}}):
2421
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
22+
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
2523
// CHECK-SIL: cond_br
2624
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF'
2725

@@ -35,12 +33,13 @@ public func span_zero_init(_ output: inout MutableSpan<Int>) {
3533
}
3634

3735
// Bounds check should be eliminated
38-
// SIL does not optimize this
39-
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop or reduce to a memcopy
36+
// SIL removes lower bounds check
37+
// LLVM removes upper bounds check and vectorizes the loop
4038

4139
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF :
4240
// CHECK-SIL: bb3({{.*}}):
4341
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
42+
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
4443
// CHECK-SIL: cond_br
4544
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF'
4645

@@ -55,11 +54,13 @@ public func span_copy_elemwise(_ output: inout MutableSpan<Int>, _ input: Span<I
5554
}
5655

5756
// Bounds check should be eliminated
58-
// SIL does not optimize this
57+
// SIL removes lower bounds check
58+
// LLVM removes upper bounds check and vectorizes the loop
5959

6060
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF :
6161
// CHECK-SIL: bb3({{.*}}):
6262
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
63+
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
6364
// CHECK-SIL: cond_br
6465
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF'
6566

@@ -73,11 +74,11 @@ public func span_append_elemwise(_ output: inout OutputSpan<Int>, _ input: Span<
7374
}
7475

7576
// Bounds check should be eliminated
76-
// SIL does not optimize this
7777

7878
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF :
7979
// CHECK-SIL: bb3({{.*}}):
8080
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
81+
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
8182
// CHECK-SIL: cond_br
8283
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'
8384

@@ -95,6 +96,7 @@ public func span_sum_wo_trap(_ output: inout MutableSpan<Int>, _ input1: Span<In
9596
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B14_sum_with_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF :
9697
// CHECK-SIL: bb3({{.*}}):
9798
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
99+
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
98100
// CHECK-SIL: cond_br
99101
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_sum_with_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'
100102

@@ -109,6 +111,7 @@ public func span_sum_with_trap(_ output: inout MutableSpan<Int>, _ input1: Span<
109111
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B12_bubble_sortyy10SpanExtras07MutableH0VySiGzF :
110112
// CHECK-SIL: bb11({{.*}}):
111113
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
114+
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
112115
// CHECK-SIL: cond_br
113116
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_bubble_sortyy10SpanExtras07MutableH0VySiGzF'
114117
public func span_bubble_sort(_ span: inout MutableSpan<Int>) {
@@ -127,7 +130,7 @@ public func span_bubble_sort(_ span: inout MutableSpan<Int>) {
127130
}
128131

129132
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests6sortedySb10SpanExtras07MutableG0VySiGF :
130-
// CHECK-SIL: bb4({{.*}}):
133+
// CHECK-SIL: bb4:
131134
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
132135
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
133136
// CHECK-SIL: cond_br

test/SILOptimizer/span_bounds_check_tests.swift

Lines changed: 68 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
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

5050
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 {
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'
8891
public 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'
126131
public 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'
163172
public 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'
199212
public 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

216227
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 {
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

229238
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 {
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'
241250
public 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'
258267
public 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'
274283
public func span_binary_search_spl(_ v: Span<Int>, _ elem: Int) -> Int? {
275284
var low = 0, high = v.count - 1

0 commit comments

Comments
 (0)