Skip to content

Commit a29f341

Browse files
committed
Auto merge of rust-lang#101963 - scottmcm:from-ptr-range-optimization, r=Mark-Simulacrum
Add a codegen test for `slice::from_ptr_range` I noticed back in rust-lang#95579 that this didn't optimize as well as it should. It's better now, after rust-lang#95837 changed the code in `from_ptr_range` and llvm/llvm-project#54824 was fixed in LLVM 15. So here's a test to keep it generating the good version.
2 parents 4c2e500 + 3356902 commit a29f341

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// compile-flags: -O
2+
// only-64bit (because we're using [ui]size)
3+
// ignore-debug (because the assertions get in the way)
4+
// min-llvm-version: 15.0 (because this is a relatively new instcombine)
5+
6+
#![crate_type = "lib"]
7+
#![feature(slice_from_ptr_range)]
8+
9+
// This is intentionally using a non-power-of-two array length,
10+
// as that's where the optimization differences show up
11+
12+
// CHECK-LABEL: @flatten_via_ptr_range
13+
#[no_mangle]
14+
pub fn flatten_via_ptr_range(slice_of_arrays: &[[i32; 13]]) -> &[i32] {
15+
// CHECK-NOT: lshr
16+
// CHECK-NOT: udiv
17+
// CHECK: mul nuw nsw i64 %{{.+}}, 13
18+
// CHECK-NOT: lshr
19+
// CHECK-NOT: udiv
20+
let r = slice_of_arrays.as_ptr_range();
21+
let r = r.start.cast()..r.end.cast();
22+
unsafe { core::slice::from_ptr_range(r) }
23+
}

0 commit comments

Comments
 (0)