diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-09-30 23:39:15 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-09-30 23:39:15 -0700 |
| commit | c7af338e6fa95dd9877a19be74b94f471233d75b (patch) | |
| tree | 0e72eda8e64f2aa620123085487a4223ce0203a8 /src/test/codegen/binary-search-index-no-bound-check.rs | |
| parent | fe217c28ffc6955f0927d8e8715d43d727debe5a (diff) | |
| download | rust-c7af338e6fa95dd9877a19be74b94f471233d75b.tar.gz rust-c7af338e6fa95dd9877a19be74b94f471233d75b.zip | |
Tell LLVM that `partition_point` returns a valid fencepost
This was already done for a successful `binary_search`, but this way `partition_point` can get similar optimizations.
Diffstat (limited to 'src/test/codegen/binary-search-index-no-bound-check.rs')
| -rw-r--r-- | src/test/codegen/binary-search-index-no-bound-check.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/test/codegen/binary-search-index-no-bound-check.rs b/src/test/codegen/binary-search-index-no-bound-check.rs index 2deabcaa6c2..c1766a4a44a 100644 --- a/src/test/codegen/binary-search-index-no-bound-check.rs +++ b/src/test/codegen/binary-search-index-no-bound-check.rs @@ -16,3 +16,23 @@ pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 { 42 } } + +// Similarly, check that `partition_point` is known to return a valid fencepost. + +// CHECK-LABEL: @unknown_split +#[no_mangle] +pub fn unknown_split(x: &[i32], i: usize) -> (&[i32], &[i32]) { + // This just makes sure that the subsequent function is looking for the + // absence of something that might actually be there. + + // CHECK: call core::panicking::panic + x.split_at(i) +} + +// CHECK-LABEL: @partition_point_split_no_bounds_check +#[no_mangle] +pub fn partition_point_split_no_bounds_check(x: &[i32], needle: i32) -> (&[i32], &[i32]) { + // CHECK-NOT: call core::panicking::panic + let i = x.partition_point(|p| p < &needle); + x.split_at(i) +} |
