11// RUN: %empty-directory(%t)
22// 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
33// 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
55
66// REQUIRES: swift_in_compiler
77// REQUIRES: swift_feature_LifetimeDependence
88// REQUIRES: swift_feature_Span
99// REQUIRES: swift_feature_AllowUnsafeAttribute
1010
11+ // REQUIRES: swift_stdlib_no_asserts, optimized_stdlib
12+
1113// In Inputs/SpanExtras.swift we have @available(macOS 9999, *):
1214// REQUIRES: OS=macosx
1315
@@ -18,11 +20,14 @@ import SpanExtras
1820// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop
1921
2022// 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
2526// 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,
2631public func span_zero_init( _ output: inout MutableSpan < Int > ) {
2732 for i in output. indices {
2833 output [ i] = 0
@@ -34,11 +39,14 @@ public func span_zero_init(_ output: inout MutableSpan<Int>) {
3439// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop or reduce to a memcopy
3540
3641// 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
4145// 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 <{{.*}}>
4250public func span_copy_elemwise( _ output: inout MutableSpan < Int > , _ input: Span < Int > ) {
4351 precondition ( output. count >= input. count)
4452 for i in input. indices {
@@ -50,11 +58,14 @@ public func span_copy_elemwise(_ output: inout MutableSpan<Int>, _ input: Span<I
5058// SIL does not optimize this
5159
5260// 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
5764// 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 <{{.*}}>
5869public func span_append_elemwise( _ output: inout OutputSpan < Int > , _ input: Span < Int > ) {
5970 for i in input. indices {
6071 output. append ( input [ i] )
@@ -65,11 +76,14 @@ public func span_append_elemwise(_ output: inout OutputSpan<Int>, _ input: Span<
6576// SIL does not optimize this
6677
6778// 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
7282// 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 <{{.*}}>
7387public func span_sum_wo_trap( _ output: inout MutableSpan < Int > , _ input1: Span < Int > , _ input2: Span < Int > ) {
7488 precondition ( input1. count == input2. count)
7589 precondition ( output. count == input1. count)
@@ -79,11 +93,11 @@ public func span_sum_wo_trap(_ output: inout MutableSpan<Int>, _ input1: Span<In
7993}
8094
8195// 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
8699// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_sum_with_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'
100+
87101public func span_sum_with_trap( _ output: inout MutableSpan < Int > , _ input1: Span < Int > , _ input2: Span < Int > ) {
88102 precondition ( input1. count == input2. count)
89103 precondition ( output. count == input1. count)
@@ -93,9 +107,9 @@ public func span_sum_with_trap(_ output: inout MutableSpan<Int>, _ input1: Span<
93107}
94108
95109// 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
99113// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_bubble_sortyy10SpanExtras07MutableH0VySiGzF'
100114public func span_bubble_sort( _ span: inout MutableSpan < Int > ) {
101115 if span. count <= 1 {
@@ -113,9 +127,10 @@ public func span_bubble_sort(_ span: inout MutableSpan<Int>) {
113127}
114128
115129// 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
119134// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests6sortedySb10SpanExtras07MutableG0VySiGF'
120135public func sorted( _ span: borrowing MutableSpan < Int > ) -> Bool {
121136 if span. count <= 1 {
0 commit comments