blob: a3aca3a2912a6c2cc31b0bc0829200dae96f817e [file] [log] [blame]
Erik Desjardins09060662020-06-15 04:50:561// no-system-llvm
2// compile-flags: -O
erikdesjardins63518502020-06-17 17:10:493// ignore-debug: the debug assertions get in the way
Erik Desjardins09060662020-06-15 04:50:564#![crate_type = "lib"]
5
Erik Desjardinse0975b92020-06-15 22:19:546// 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 Desjardins09060662020-06-15 04:50:5612// CHECK-LABEL: @already_sliced_no_bounds_check
13#[no_mangle]
14pub fn already_sliced_no_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
Lukas Kalbertodt0d64b012020-07-19 14:12:5015 // CHECK: slice_end_index_len_fail
Erik Desjardins09060662020-06-15 04:50:5616 // 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 Desjardinse0975b92020-06-15 22:19:5423// CHECK-LABEL: @already_sliced_no_bounds_check_exact
24#[no_mangle]
25pub fn already_sliced_no_bounds_check_exact(a: &[u8], b: &[u8], c: &mut [u8]) {
Lukas Kalbertodt0d64b012020-07-19 14:12:5026 // CHECK: slice_end_index_len_fail
Erik Desjardinse0975b92020-06-15 22:19:5427 // 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 Desjardins09060662020-06-15 04:50:5635// CHECK-LABEL: @already_sliced_bounds_check
36#[no_mangle]
37pub fn already_sliced_bounds_check(a: &[u8], b: &[u8], c: &mut [u8]) {
Lukas Kalbertodt0d64b012020-07-19 14:12:5038 // CHECK: slice_end_index_len_fail
Erik Desjardins09060662020-06-15 04:50:5639 // 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}