Auto merge of #122325 - erikdesjardins:array, r= · rust-lang/rust@7ba692d (original) (raw)

9 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -2378,7 +2378,8 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
2378 2378 }
2379 2379 let offsets = args[1].immediate();
2380 2380
2381 -return Ok(bx.gep(bx.backend_type(layout), ptrs, &[offsets]));
2381 +let elem_sized_type = bx.type_array(bx.type_i8(), layout.size.bytes());
2382 +return Ok(bx.gep(elem_sized_type, ptrs, &[offsets]));
2382 2383 }
2383 2384
2384 2385 if name == sym::simd_saturating_add |
Original file line number Diff line number Diff line change
@@ -139,7 +139,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
139 139 let layout = bx.layout_of(ty);
140 140 let ptr = args[0].immediate();
141 141 let offset = args[1].immediate();
142 - bx.gep(bx.backend_type(layout), ptr, &[offset])
142 +let elem_sized_type = bx.type_array(bx.type_i8(), layout.size.bytes());
143 + bx.gep(elem_sized_type, ptr, &[offset])
143 144 }
144 145 sym::copy => {
145 146 copy_intrinsic(
Original file line number Diff line number Diff line change
@@ -356,12 +356,9 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
356 356 layout.size
357 357 };
358 358
359 +let elem_sized_type = bx.type_array(bx.type_i8(), layout.size.bytes());
359 360 PlaceRef {
360 -llval: bx.inbounds_gep(
361 - bx.cx().backend_type(self.layout),
362 -self.llval,
363 -&[bx.cx().const_usize(0), llindex],
364 -),
361 +llval: bx.inbounds_gep(elem_sized_type, self.llval, &[llindex]),
365 362 llextra: None,
366 363 layout,
367 364 align: self.align.restrict_for_offset(offset),
Original file line number Diff line number Diff line change
@@ -862,8 +862,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
862 862 // so offsetting a pointer to ZST is a noop.
863 863 lhs
864 864 } else {
865 -let llty = bx.cx().backend_type(pointee_layout);
866 - bx.inbounds_gep(llty, lhs, &[rhs])
865 +let elem_sized_type = bx.type_array(bx.type_i8(), pointee_layout.size.bytes());
866 + bx.inbounds_gep(elem_sized_type, lhs, &[rhs])
867 867 }
868 868 }
869 869 mir::BinOp::Shl => common::build_masked_lshift(bx, lhs, rhs),
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
1 +//@ compile-flags: -O
2 +
3 +#![crate_type = "lib"]
4 +#![feature(core_intrinsics)]
5 +
6 +use std::intrinsics::arith_offset;
7 +
8 +// CHECK-LABEL: ptr @arith_offset_zst
9 +// CHECK-SAME: (ptr noundef{{.*}} %p, [[SIZE:i[0-9]+]] noundef %d)
10 +#[no_mangle]
11 +pub unsafe fn arith_offset_zst(p: *const (), d: isize) -> *const () {
12 +// CHECK-NOT: getelementptr
13 +// CHECK: ret ptr %p
14 +arith_offset(p, d)
15 +}
16 +
17 +// CHECK-LABEL: ptr @arith_offset_u32
18 +// CHECK-SAME: (ptr noundef{{.*}} %p, [[SIZE]] noundef %d)
19 +#[no_mangle]
20 +pub unsafe fn arith_offset_u32(p: *const u32, d: isize) -> *const u32 {
21 +// CHECK: %[[R:.*]] = getelementptr [4 x i8], ptr %p, [[SIZE]] %d
22 +// CHECK-NEXT: ret ptr %[[R]]
23 +arith_offset(p, d)
24 +}
25 +
26 +// CHECK-LABEL: ptr @arith_offset_u64
27 +// CHECK-SAME: (ptr noundef{{.*}} %p, [[SIZE]] noundef %d)
28 +#[no_mangle]
29 +pub unsafe fn arith_offset_u64(p: *const u64, d: isize) -> *const u64 {
30 +// CHECK: %[[R:.*]] = getelementptr [8 x i8], ptr %p, [[SIZE]] %d
31 +// CHECK-NEXT: ret ptr %[[R]]
32 +arith_offset(p, d)
33 +}
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ pub unsafe fn offset_zst(p: *const (), d: usize) -> *const () {
18 18 // CHECK-SAME: (ptr noundef %p, [[SIZE]] noundef %d)
19 19 #[no_mangle]
20 20 pub unsafe fn offset_isize(p: *const u32, d: isize) -> *const u32 {
21 -// CHECK: %[[R:.*]] = getelementptr inbounds i32, ptr %p, [[SIZE]] %d
21 +// CHECK: %[[R:.*]] = getelementptr inbounds [4 x i8], ptr %p, [[SIZE]] %d
22 22 // CHECK-NEXT: ret ptr %[[R]]
23 23 offset(p, d)
24 24 }
@@ -27,7 +27,7 @@ pub unsafe fn offset_isize(p: *const u32, d: isize) -> *const u32 {
27 27 // CHECK-SAME: (ptr noundef %p, [[SIZE]] noundef %d)
28 28 #[no_mangle]
29 29 pub unsafe fn offset_usize(p: *const u64, d: usize) -> *const u64 {
30 -// CHECK: %[[R:.*]] = getelementptr inbounds i64, ptr %p, [[SIZE]] %d
30 +// CHECK: %[[R:.*]] = getelementptr inbounds [8 x i8], ptr %p, [[SIZE]] %d
31 31 // CHECK-NEXT: ret ptr %[[R]]
32 32 offset(p, d)
33 33 }
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
6 6 // CHECK-SAME: [[WORD:i[0-9]+]] noundef %n)
7 7 #[no_mangle]
8 8 pub unsafe fn i32_add(p: *const i32, n: usize) -> *const i32 {
9 -// CHECK: %[[TEMP:.+]] = getelementptr inbounds i32, ptr %p, [[WORD]] %n
9 +// CHECK: %[[TEMP:.+]] = getelementptr inbounds [4 x i8], ptr %p, [[WORD]] %n
10 10 // CHECK: ret ptr %[[TEMP]]
11 11 p.add(n)
12 12 }
@@ -18,7 +18,7 @@ pub unsafe fn i32_add(p: *const i32, n: usize) -> *const i32 {
18 18 #[no_mangle]
19 19 pub unsafe fn i32_sub(p: *const i32, n: usize) -> *const i32 {
20 20 // CHECK: %[[DELTA:.+]] = sub nsw [[WORD]] 0, %n
21 -// CHECK: %[[TEMP:.+]] = getelementptr inbounds i32, ptr %p, [[WORD]] %[[DELTA]]
21 +// CHECK: %[[TEMP:.+]] = getelementptr inbounds [4 x i8], ptr %p, [[WORD]] %[[DELTA]]
22 22 // CHECK: ret ptr %[[TEMP]]
23 23 p.sub(n)
24 24 }
@@ -27,7 +27,7 @@ pub unsafe fn i32_sub(p: *const i32, n: usize) -> *const i32 {
27 27 // CHECK-SAME: [[WORD:i[0-9]+]] noundef %d)
28 28 #[no_mangle]
29 29 pub unsafe fn i32_offset(p: *const i32, d: isize) -> *const i32 {
30 -// CHECK: %[[TEMP:.+]] = getelementptr inbounds i32, ptr %p, [[WORD]] %d
30 +// CHECK: %[[TEMP:.+]] = getelementptr inbounds [4 x i8], ptr %p, [[WORD]] %d
31 31 // CHECK: ret ptr %[[TEMP]]
32 32 p.offset(d)
33 33 }
Original file line number Diff line number Diff line change
@@ -18,9 +18,16 @@ pub struct SimdConstPtr<T, const LANES: usize>([*const T; LANES]);
18 18 #[repr(simd)]
19 19 pub struct Simd<T, const LANES: usize>([T; LANES]);
20 20
21 -// CHECK-LABEL: smoke
21 +// CHECK-LABEL: u8_offset
22 22 #[no_mangle]
23 -pub fn smoke(ptrs: SimdConstPtr<u8, 8>, offsets: Simd<usize, 8>) -> SimdConstPtr<u8, 8> {
24 -// CHECK: getelementptr i8, <8 x ptr> %0, <8 x i64> %1
23 +pub fn u8_offset(ptrs: SimdConstPtr<u8, 8>, offsets: Simd<usize, 8>) -> SimdConstPtr<u8, 8> {
24 +// CHECK: getelementptr [1 x i8], <8 x ptr> %0, <8 x i64> %1
25 +unsafe { simd_arith_offset(ptrs, offsets) }
26 +}
27 +
28 +// CHECK-LABEL: u64_offset
29 +#[no_mangle]
30 +pub fn u64_offset(ptrs: SimdConstPtr<u64, 8>, offsets: Simd<usize, 8>) -> SimdConstPtr<u64, 8> {
31 +// CHECK: getelementptr [8 x i8], <8 x ptr> %0, <8 x i64> %1
25 32 unsafe { simd_arith_offset(ptrs, offsets) }
26 33 }
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ pub fn slice_iter_next_back<'a>(it: &mut std::slice::Iter<'a, u32>) -> Option<&'
54 54 #[no_mangle]
55 55 pub fn slice_iter_new(slice: &[u32]) -> std::slice::Iter<'_, u32> {
56 56 // CHECK-NOT: slice
57 -// CHECK: %[[END:.+]] = getelementptr inbounds i32{{.+}} %slice.0{{.+}} %slice.1
57 +// CHECK: %[[END:.+]] = getelementptr inbounds [4 x i8]{{.+}} %slice.0{{.+}} %slice.1
58 58 // CHECK-NOT: slice
59 59 // CHECK: insertvalue {{.+}} ptr %slice.0, 0
60 60 // CHECK-NOT: slice
@@ -69,7 +69,7 @@ pub fn slice_iter_new(slice: &[u32]) -> std::slice::Iter<'_, u32> {
69 69 #[no_mangle]
70 70 pub fn slice_iter_mut_new(slice: &mut [u32]) -> std::slice::IterMut<'_, u32> {
71 71 // CHECK-NOT: slice
72 -// CHECK: %[[END:.+]] = getelementptr inbounds i32{{.+}} %slice.0{{.+}} %slice.1
72 +// CHECK: %[[END:.+]] = getelementptr inbounds [4 x i8]{{.+}} %slice.0{{.+}} %slice.1
73 73 // CHECK-NOT: slice
74 74 // CHECK: insertvalue {{.+}} ptr %slice.0, 0
75 75 // CHECK-NOT: slice