Skip to content

[Test] Enable test for all platforms and update check lines #79275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions test/SILOptimizer/mutable_span_bounds_check_tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,16 @@

// REQUIRES: swift_stdlib_no_asserts, optimized_stdlib

// In Inputs/SpanExtras.swift we have @available(macOS 9999, *):
// REQUIRES: OS=macosx

import SpanExtras

// Bounds check should be eliminated
// SIL does not optimize this
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop
// SIL removes lower bounds check
// LLVM removes upper bounds check and vectorizes the loop

// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF :
// CHECK-SIL: bb3({{.*}}):
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B10_zero_inityy10SpanExtras07MutableH0VySiGzF'

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

// Bounds check should be eliminated
// SIL does not optimize this
// LLVM leaves behind a lower bound check outside the loop, does not vectorize the loop or reduce to a memcopy
// SIL removes lower bounds check
// LLVM removes upper bounds check and vectorizes the loop

// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF :
// CHECK-SIL: bb3({{.*}}):
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B14_copy_elemwiseyy10SpanExtras07MutableH0VySiGz_s0H0VySiGtF'

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

// Bounds check should be eliminated
// SIL does not optimize this
// SIL removes lower bounds check
// LLVM removes upper bounds check and vectorizes the loop

// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF :
// CHECK-SIL: bb3({{.*}}):
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B16_append_elemwiseyy10SpanExtras06OutputH0VySiGz_s0H0VySiGtF'

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

// Bounds check should be eliminated
// SIL does not optimize this

// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF :
// CHECK-SIL: bb3({{.*}}):
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL-NOT: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s31mutable_span_bounds_check_tests0B12_sum_wo_trapyy10SpanExtras07MutableI0VySiGz_s0I0VySiGAItF'

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

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

// CHECK-SIL-LABEL: sil @$s31mutable_span_bounds_check_tests6sortedySb10SpanExtras07MutableG0VySiGF :
// CHECK-SIL: bb4({{.*}}):
// CHECK-SIL: bb4:
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL: cond_fail {{.*}}, "precondition failure"
// CHECK-SIL: cond_br
Expand Down
127 changes: 68 additions & 59 deletions test/SILOptimizer/span_bounds_check_tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
// A lower bounds check is left behind in the entry block

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A29_sum_iterate_to_count_wo_trapySis4SpanVySiGF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A29_sum_iterate_to_count_wo_trapySis4SpanVySiGF'

// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A29_sum_iterate_to_count_wo_trapySis4SpanVySiGF"
Expand All @@ -41,10 +41,10 @@ public func span_sum_iterate_to_count_wo_trap(_ v: Span<Int>) -> Int {
// A lower bounds check is left behind in the entry block

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A31_sum_iterate_to_count_with_trapySis4SpanVySiGF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_sum_iterate_to_count_with_trapySis4SpanVySiGF'

public func span_sum_iterate_to_count_with_trap(_ v: Span<Int>) -> Int {
Expand All @@ -61,10 +61,10 @@ public func span_sum_iterate_to_count_with_trap(_ v: Span<Int>) -> Int {
// A lower bounds check is left behind in the entry block

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A31_sum_iterate_to_unknown_wo_trapySis4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_sum_iterate_to_unknown_wo_trapySis4SpanVySiG_SitF'

// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A31_sum_iterate_to_unknown_wo_trapySis4SpanVySiG_SitF"
Expand All @@ -78,12 +78,15 @@ public func span_sum_iterate_to_unknown_wo_trap(_ v: Span<Int>, _ n: Int) -> Int
}

// Bounds check should be hoisted
// SIL removes lower bounds check from the loop
// LLVM removes the upper bounds check from the loop
// A lower bounds check is left behind in the entry block

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A33_sum_iterate_to_unknown_with_trapySis4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A33_sum_iterate_to_unknown_with_trapySis4SpanVySiG_SitF'
public func span_sum_iterate_to_unknown_with_trap(_ v: Span<Int>, _ n: Int) -> Int {
var sum = 0
Expand All @@ -98,10 +101,10 @@ public func span_sum_iterate_to_unknown_with_trap(_ v: Span<Int>, _ n: Int) -> I
// LLVM removes the upper bounds check from the loop and then vectorizes

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count1_wo_trapySis4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count1_wo_trapySis4SpanVySiG_SitF'

// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count1_wo_trapySis4SpanVySiG_SitF"
Expand All @@ -116,12 +119,14 @@ public func span_sum_iterate_to_deducible_count1_wo_trap(_ v: Span<Int>, _ n: In
}

// Bounds check should be eliminated
// SIL removes lower bounds check from the loop
// LLVM does not eliminate redundant bounds check

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count1_with_trapySis4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count1_with_trapySis4SpanVySiG_SitF'
public func span_sum_iterate_to_deducible_count1_with_trap(_ v: Span<Int>, _ n: Int) -> Int {
var sum = 0
Expand All @@ -133,12 +138,14 @@ public func span_sum_iterate_to_deducible_count1_with_trap(_ v: Span<Int>, _ n:
}

// Bounds check should be eliminated
// SIL removes lower bounds check from the loop
// LLVM removes upper bounds check and vectorizes the loop

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count2_wo_trapySis4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count2_wo_trapySis4SpanVySiG_SitF'

// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A40_sum_iterate_to_deducible_count2_wo_trapySis4SpanVySiG_SitF"
Expand All @@ -153,12 +160,14 @@ public func span_sum_iterate_to_deducible_count2_wo_trap(_ v: Span<Int>, _ n: In
}

// Bounds check should be eliminated
// SIL removes lower bounds check from the loop
// LLVM does not eliminate redundant bounds check

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count2_with_trapySis4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A42_sum_iterate_to_deducible_count2_with_trapySis4SpanVySiG_SitF'
public func span_sum_iterate_to_deducible_count2_with_trap(_ v: Span<Int>, _ n: Int) -> Int {
var sum = 0
Expand All @@ -170,12 +179,14 @@ public func span_sum_iterate_to_deducible_count2_with_trap(_ v: Span<Int>, _ n:
}

// Bounds check should be eliminated
// SIL removes lower bounds check from the loop
// LLVM removes upper bounds check and vectorizes the loop

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A29_iterate_over_indices_wo_trapySis4SpanVySiGF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A29_iterate_over_indices_wo_trapySis4SpanVySiGF'

// CHECK-IR: define {{.*}} @"$s23span_bounds_check_tests0A29_iterate_over_indices_wo_trapySis4SpanVySiGF"
Expand All @@ -189,12 +200,14 @@ public func span_iterate_over_indices_wo_trap(_ v: Span<Int>) -> Int {
}

// Bounds check should be eliminated
// SIL removes lower bounds check from the loop
// LLVM does not eliminate redundant bounds check

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A31_iterate_over_indices_with_trapySis4SpanVySiGF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A31_iterate_over_indices_with_trapySis4SpanVySiGF'
public func span_iterate_over_indices_with_trap(_ v: Span<Int>) -> Int {
var sum = 0
Expand All @@ -207,10 +220,8 @@ public func span_iterate_over_indices_with_trap(_ v: Span<Int>) -> Int {
// Eliminate duplicate bounds check

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A17_element_equalityySbs4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A17_element_equalityySbs4SpanVySiG_SitF'

public func span_element_equality(_ v: Span<Int>, _ i: Int) -> Bool {
Expand All @@ -220,10 +231,8 @@ public func span_element_equality(_ v: Span<Int>, _ i: Int) -> Bool {
// Eliminate duplicate bounds check

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A12_element_sumySis4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A12_element_sumySis4SpanVySiG_SitF'

public func span_element_sum(_ v: Span<Int>, _ i: Int) -> Int {
Expand All @@ -233,10 +242,10 @@ public func span_element_sum(_ v: Span<Int>, _ i: Int) -> Int {
// Bounds check should be eliminated

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A7_searchySiSgs4SpanVyxG_xtSQRzlF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3:
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A7_searchySiSgs4SpanVyxG_xtSQRzlF'
public func span_search<T : Equatable>(_ v: Span<T>, _ elem: T) -> Int? {
for i in v.indices {
Expand All @@ -250,10 +259,10 @@ public func span_search<T : Equatable>(_ v: Span<T>, _ elem: T) -> Int? {
// Bounds check should be eliminated

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A11_search_splySiSgs4SpanVySiG_SitF :
// CHECK: bb3
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK-NOT: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb3:
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A11_search_splySiSgs4SpanVySiG_SitF'
public func span_search_spl(_ v: Span<Int>, _ elem: Int) -> Int? {
for i in v.indices {
Expand All @@ -267,9 +276,9 @@ public func span_search_spl(_ v: Span<Int>, _ elem: Int) -> Int? {
// Bounds check should be eliminated

// CHECK-SIL-LABEL: sil @$s23span_bounds_check_tests0A18_binary_search_splySiSgs4SpanVySiG_SitF :
// CHECK: bb2
// CHECK: cond_fail {{.*}}, "Index out of bounds"
// CHECK: cond_br
// CHECK-SIL: bb2
// CHECK-SIL: cond_fail {{.*}}, "Index out of bounds"
// CHECK-SIL: cond_br
// CHECK-SIL-LABEL: } // end sil function '$s23span_bounds_check_tests0A18_binary_search_splySiSgs4SpanVySiG_SitF'
public func span_binary_search_spl(_ v: Span<Int>, _ elem: Int) -> Int? {
var low = 0, high = v.count - 1
Expand Down