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
@@ -18,11 +18,14 @@ import SpanExtras
18
18
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop
19
19
20
20
// 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
21
+ // CHECK-SIL: bb3({{.*}}):
22
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
23
+ // CHECK-SIL: cond_br
25
24
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF'
25
+
26
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF"
27
+ // CHECK-IR: vector.body
28
+ // CHECK-IR: store <{{.*}}> zeroinitializer,
26
29
public func span_zero_init( _ output: inout MutableSpan < Int > ) {
27
30
for i in output. indices {
28
31
output [ i] = 0
@@ -34,11 +37,14 @@ public func span_zero_init(_ output: inout MutableSpan<Int>) {
34
37
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop or reduce to a memcopy
35
38
36
39
// 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
40
+ // CHECK-SIL: bb3({{.*}}):
41
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
42
+ // CHECK-SIL: cond_br
41
43
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF'
44
+
45
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF"
46
+ // CHECK-IR: vector.body
47
+ // CHECK-IR: store <{{.*}}>
42
48
public func span_copy_elemwise( _ output: inout MutableSpan < Int > , _ input: Span < Int > ) {
43
49
precondition ( output. count >= input. count)
44
50
for i in input. indices {
@@ -50,11 +56,14 @@ public func span_copy_elemwise(_ output: inout MutableSpan<Int>, _ input: Span<I
50
56
// SIL does not optimize this
51
57
52
58
// 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
59
+ // CHECK-SIL: bb3({{.*}}):
60
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
61
+ // CHECK-SIL: cond_br
57
62
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF'
63
+
64
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF"
65
+ // CHECK-IR: vector.body
66
+ // CHECK-IR: store <{{.*}}>
58
67
public func span_append_elemwise( _ output: inout OutputSpan < Int > , _ input: Span < Int > ) {
59
68
for i in input. indices {
60
69
output. append ( input [ i] )
@@ -65,11 +74,14 @@ public func span_append_elemwise(_ output: inout OutputSpan<Int>, _ input: Span<
65
74
// SIL does not optimize this
66
75
67
76
// 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
77
+ // CHECK-SIL: bb3({{.*}}):
78
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
79
+ // CHECK-SIL: cond_br
72
80
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'
81
+
82
+ // CHECK-IR: define {{.*}} void @"$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF"
83
+ // CHECK-IR: vector.body
84
+ // CHECK-IR: store <{{.*}}>
73
85
public func span_sum_wo_trap( _ output: inout MutableSpan < Int > , _ input1: Span < Int > , _ input2: Span < Int > ) {
74
86
precondition ( input1. count == input2. count)
75
87
precondition ( output. count == input1. count)
@@ -79,11 +91,11 @@ public func span_sum_wo_trap(_ output: inout MutableSpan<Int>, _ input1: Span<In
79
91
}
80
92
81
93
// 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
94
+ // CHECK-SIL: bb3({{.*}}):
95
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
96
+ // CHECK-SIL: cond_br
86
97
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_sum_with_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'
98
+
87
99
public func span_sum_with_trap( _ output: inout MutableSpan < Int > , _ input1: Span < Int > , _ input2: Span < Int > ) {
88
100
precondition ( input1. count == input2. count)
89
101
precondition ( output. count == input1. count)
@@ -93,9 +105,9 @@ public func span_sum_with_trap(_ output: inout MutableSpan<Int>, _ input1: Span<
93
105
}
94
106
95
107
// 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
108
+ // CHECK-SIL: bb11({{.*}}) :
109
+ // CHECK-SIL : cond_fail {{.*}}, "precondition failure "
110
+ // CHECK-SIL : cond_br
99
111
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_bubble_sortyy10SpanExtras07MutableH0VySiGzF'
100
112
public func span_bubble_sort( _ span: inout MutableSpan < Int > ) {
101
113
if span. count <= 1 {
@@ -113,9 +125,10 @@ public func span_bubble_sort(_ span: inout MutableSpan<Int>) {
113
125
}
114
126
115
127
// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests6sortedySb10SpanExtras07MutableG0VySiGF :
116
- // CHECK: bb4:
117
- // CHECK: cond_fail {{.*}}, "Index out of bounds"
118
- // CHECK: cond_br
128
+ // CHECK-SIL: bb4({{.*}}):
129
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
130
+ // CHECK-SIL: cond_fail {{.*}}, "precondition failure"
131
+ // CHECK-SIL: cond_br
119
132
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests6sortedySb10SpanExtras07MutableG0VySiGF'
120
133
public func sorted( _ span: borrowing MutableSpan < Int > ) -> Bool {
121
134
if span. count <= 1 {
0 commit comments