diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:18:58 +0000 |
commit | a4b7ed7a42c716ab9f05e351f003d589124fd55d (patch) | |
tree | b620cd3f223850b28716e474e80c58059dca5dd4 /tests/codegen/intrinsics/offset_from.rs | |
parent | Adding upstream version 1.67.1+dfsg1. (diff) | |
download | rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip |
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/codegen/intrinsics/offset_from.rs')
-rw-r--r-- | tests/codegen/intrinsics/offset_from.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/codegen/intrinsics/offset_from.rs b/tests/codegen/intrinsics/offset_from.rs new file mode 100644 index 000000000..d0de4c835 --- /dev/null +++ b/tests/codegen/intrinsics/offset_from.rs @@ -0,0 +1,36 @@ +// compile-flags: -C opt-level=1 +// only-64bit (because we're using [ui]size) + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +//! Basic optimizations are enabled because otherwise `x86_64-gnu-nopt` had an alloca. +//! Uses a type with non-power-of-two size to avoid normalizations to shifts. + +use std::intrinsics::*; + +type RGB = [u8; 3]; + +// CHECK-LABEL: @offset_from_odd_size +#[no_mangle] +pub unsafe fn offset_from_odd_size(a: *const RGB, b: *const RGB) -> isize { + // CHECK: start + // CHECK-NEXT: ptrtoint + // CHECK-NEXT: ptrtoint + // CHECK-NEXT: sub i64 + // CHECK-NEXT: sdiv exact i64 %{{[0-9]+}}, 3 + // CHECK-NEXT: ret i64 + ptr_offset_from(a, b) +} + +// CHECK-LABEL: @offset_from_unsigned_odd_size +#[no_mangle] +pub unsafe fn offset_from_unsigned_odd_size(a: *const RGB, b: *const RGB) -> usize { + // CHECK: start + // CHECK-NEXT: ptrtoint + // CHECK-NEXT: ptrtoint + // CHECK-NEXT: sub nuw i64 + // CHECK-NEXT: udiv exact i64 %{{[0-9]+}}, 3 + // CHECK-NEXT: ret i64 + ptr_offset_from_unsigned(a, b) +} |