Erik Desjardins | 0906066 | 2020-06-15 04:50:56 | [diff] [blame] | 1 | // no-system-llvm |
| 2 | // compile-flags: -O |
erikdesjardins | 6351850 | 2020-06-17 17:10:49 | [diff] [blame] | 3 | // ignore-debug: the debug assertions get in the way |
Erik Desjardins | 0906066 | 2020-06-15 04:50:56 | [diff] [blame] | 4 | #![crate_type = "lib"] |
| 5 | |
Erik Desjardins | e0975b9 | 2020-06-15 22:19:54 | [diff] [blame] | 6 | // Make sure no bounds checks are emitted in the loop when upfront slicing |
| 7 | // ensures that the slices are big enough. |
| 8 | // In particular, bounds checks were not always optimized out if the upfront |
| 9 | // check was for a greater len than the loop requires. |
| 10 | // (i.e. `already_sliced_no_bounds_check` was not always optimized even when |
| 11 | // `already_sliced_no_bounds_check_exact` was) |
Erik Desjardins | 0906066 | 2020-06-15 04:50:56 | [diff] [blame] | 12 | // CHECK-LABEL: @already_sliced_no_bounds_check |
| 13 | #[no_mangle] |
| 14 | pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) { |
Lukas Kalbertodt | 0d64b01 | 2020-07-19 14:12:50 | [diff] [blame] | 15 | // CHECK: slice_end_index_len_fail |
Erik Desjardins | 0906066 | 2020-06-15 04:50:56 | [diff] [blame] | 16 | // CHECK-NOT: panic_bounds_check |
| 17 | let _ = (&a[..2048], &b[..2048], &mut c[..2048]); |
| 18 | for i in 0..1024 { |
| 19 | c[i] = a[i] ^ b[i]; |
| 20 | } |
| 21 | } |
| 22 | |
Erik Desjardins | e0975b9 | 2020-06-15 22:19:54 | [diff] [blame] | 23 | // CHECK-LABEL: @already_sliced_no_bounds_check_exact |
| 24 | #[no_mangle] |
| 25 | pub fn already_sliced_no_bounds_check_exact(a: &[u8], b: &[u8], c: &mut [u8]) { |
Lukas Kalbertodt | 0d64b01 | 2020-07-19 14:12:50 | [diff] [blame] | 26 | // CHECK: slice_end_index_len_fail |
Erik Desjardins | e0975b9 | 2020-06-15 22:19:54 | [diff] [blame] | 27 | // CHECK-NOT: panic_bounds_check |
| 28 | let _ = (&a[..1024], &b[..1024], &mut c[..1024]); |
| 29 | for i in 0..1024 { |
| 30 | c[i] = a[i] ^ b[i]; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // Make sure we're checking for the right thing: there can be a panic if the slice is too small. |
Erik Desjardins | 0906066 | 2020-06-15 04:50:56 | [diff] [blame] | 35 | // CHECK-LABEL: @already_sliced_bounds_check |
| 36 | #[no_mangle] |
| 37 | pub fn already_sliced_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) { |
Lukas Kalbertodt | 0d64b01 | 2020-07-19 14:12:50 | [diff] [blame] | 38 | // CHECK: slice_end_index_len_fail |
Erik Desjardins | 0906066 | 2020-06-15 04:50:56 | [diff] [blame] | 39 | // CHECK: panic_bounds_check |
| 40 | let _ = (&a[..1023], &b[..2048], &mut c[..2048]); |
| 41 | for i in 0..1024 { |
| 42 | c[i] = a[i] ^ b[i]; |
| 43 | } |
| 44 | } |