1
1
// RUN: %empty-directory(%t)
2
2
// RUN: %target-swift-frontend -emit-module-path %t/SpanExtras.swiftmodule %S/Inputs/SpanExtras.swift -enable-builtin-module -enable-experimental-feature LifetimeDependence -enable-experimental-feature AllowUnsafeAttribute -enable-experimental-feature Span -O
3
3
// RUN: %target-swift-frontend -I %t -O -emit-sil %s -enable-experimental-feature Span -disable-availability-checking | %FileCheck %s --check-prefix=CHECK-SIL
4
- // RUN: %target-swift-frontend -I %t -O -emit-ir %s -enable-experimental-feature Span -disable-availability-checking
4
+ // RUN: %target-swift-frontend -I %t -O -emit-ir %s -enable-experimental-feature Span -disable-availability-checking | %FileCheck %s --check-prefix=CHECK-IR
5
5
6
6
// REQUIRES: swift_in_compiler
7
7
// REQUIRES: swift_feature_LifetimeDependence
8
8
// REQUIRES: swift_feature_Span
9
9
// REQUIRES: swift_feature_AllowUnsafeAttribute
10
10
11
+ // REQUIRES: swift_stdlib_no_asserts, optimized_stdlib
12
+
11
13
// In Inputs/SpanExtras.swift we have @available(macOS 9999, *):
12
14
// REQUIRES: OS=macosx
13
15
@@ -18,11 +20,14 @@ import SpanExtras
18
20
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop
19
21
20
22
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF :
21
- // CHECK: bb2:
22
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
23
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
24
- // CHECK: cond_br
23
+ // CHECK-SIL: bb3({{.*}}):
24
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
25
+ // CHECK-SIL: cond_br
25
26
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF'
27
+
28
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF"
29
+ // CHECK-IR: vector.body
30
+ // CHECK-IR: store <{{.*}}> zeroinitializer,
26
31
public func span_zero_init( _ output: inout MutableSpan < Int > ) {
27
32
for i in output. indices {
28
33
output [ i] = 0
@@ -34,11 +39,14 @@ public func span_zero_init(_ output: inout MutableSpan<Int>) {
34
39
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop or reduce to a memcopy
35
40
36
41
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF :
37
- // CHECK: bb2:
38
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
39
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
40
- // CHECK: cond_br
42
+ // CHECK-SIL: bb3({{.*}}):
43
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
44
+ // CHECK-SIL: cond_br
41
45
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF'
46
+
47
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF"
48
+ // CHECK-IR: vector.body
49
+ // CHECK-IR: store <{{.*}}>
42
50
public func span_copy_elemwise( _ output: inout MutableSpan < Int > , _ input: Span < Int > ) {
43
51
precondition ( output. count >= input. count)
44
52
for i in input. indices {
@@ -50,11 +58,14 @@ public func span_copy_elemwise(_ output: inout MutableSpan<Int>, _ input: Span<I
50
58
// SIL does not optimize this
51
59
52
60
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF :
53
- // CHECK: bb2:
54
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
55
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
56
- // CHECK: cond_br
61
+ // CHECK-SIL: bb3({{.*}}):
62
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
63
+ // CHECK-SIL: cond_br
57
64
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF'
65
+
66
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF"
67
+ // CHECK-IR: vector.body
68
+ // CHECK-IR: store <{{.*}}>
58
69
public func span_append_elemwise( _ output: inout OutputSpan < Int > , _ input: Span < Int > ) {
59
70
for i in input. indices {
60
71
output. append ( input [ i] )
@@ -65,11 +76,14 @@ public func span_append_elemwise(_ output: inout OutputSpan<Int>, _ input: Span<
65
76
// SIL does not optimize this
66
77
67
78
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF :
68
- // CHECK: bb2:
69
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
70
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
71
- // CHECK: cond_br
79
+ // CHECK-SIL: bb3({{.*}}):
80
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
81
+ // CHECK-SIL: cond_br
72
82
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'
83
+
84
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF"
85
+ // CHECK-IR: vector.body
86
+ // CHECK-IR: store <{{.*}}>
73
87
public func span_sum_wo_trap( _ output: inout MutableSpan < Int > , _ input1: Span < Int > , _ input2: Span < Int > ) {
74
88
precondition ( input1. count == input2. count)
75
89
precondition ( output. count == input1. count)
@@ -79,11 +93,11 @@ public func span_sum_wo_trap(_ output: inout MutableSpan<Int>, _ input1: Span<In
79
93
}
80
94
81
95
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B14_sum_with_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF :
82
- // CHECK: bb2:
83
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
84
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
85
- // CHECK: cond_br
96
+ // CHECK-SIL: bb3({{.*}}):
97
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
98
+ // CHECK-SIL: cond_br
86
99
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_sum_with_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'
100
+
87
101
public func span_sum_with_trap( _ output: inout MutableSpan < Int > , _ input1: Span < Int > , _ input2: Span < Int > ) {
88
102
precondition ( input1. count == input2. count)
89
103
precondition ( output. count == input1. count)
@@ -93,9 +107,9 @@ public func span_sum_with_trap(_ output: inout MutableSpan<Int>, _ input1: Span<
93
107
}
94
108
95
109
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B12_bubble_sortyy10SpanExtras07MutableH0VySiGzF :
96
- // CHECK: bb10 :
97
- // CHECK: cond_fail {{.*}}, "Index out of bounds "
98
- // CHECK: cond_br
110
+ // CHECK-SIL: bb11({{.*}}) :
111
+ // CHECK-SIL : cond_fail {{.*}}, "precondition failure "
112
+ // CHECK-SIL : cond_br
99
113
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_bubble_sortyy10SpanExtras07MutableH0VySiGzF'
100
114
public func span_bubble_sort( _ span: inout MutableSpan < Int > ) {
101
115
if span. count <= 1 {
@@ -113,9 +127,10 @@ public func span_bubble_sort(_ span: inout MutableSpan<Int>) {
113
127
}
114
128
115
129
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests6sortedySb10SpanExtras07MutableG0VySiGF :
116
- // CHECK: bb4:
117
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
118
- // CHECK: cond_br
130
+ // CHECK-SIL: bb4({{.*}}):
131
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
132
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
133
+ // CHECK-SIL: cond_br
119
134
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests6sortedySb10SpanExtras07MutableG0VySiGF'
120
135
public func sorted( _ span: borrowing MutableSpan < Int > ) -> Bool {
121
136
if span. count <= 1 {
0 commit comments