diff options
Diffstat (limited to '')
-rw-r--r-- | tests/codegen/intrinsics/compare_bytes.rs | 34 | ||||
-rw-r--r-- | tests/codegen/intrinsics/mask.rs | 2 | ||||
-rw-r--r-- | tests/codegen/intrinsics/nontemporal.rs | 2 | ||||
-rw-r--r-- | tests/codegen/intrinsics/offset.rs | 1 | ||||
-rw-r--r-- | tests/codegen/intrinsics/transmute-niched.rs | 17 | ||||
-rw-r--r-- | tests/codegen/intrinsics/transmute-x64.rs | 13 | ||||
-rw-r--r-- | tests/codegen/intrinsics/transmute.rs | 91 |
7 files changed, 93 insertions, 67 deletions
diff --git a/tests/codegen/intrinsics/compare_bytes.rs b/tests/codegen/intrinsics/compare_bytes.rs new file mode 100644 index 000000000..e69224d81 --- /dev/null +++ b/tests/codegen/intrinsics/compare_bytes.rs @@ -0,0 +1,34 @@ +// revisions: INT32 INT16 +// compile-flags: -O +// [INT32] ignore-16bit +// [INT16] only-16bit + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +use std::intrinsics::compare_bytes; + +#[no_mangle] +// CHECK-LABEL: @bytes_cmp( +pub unsafe fn bytes_cmp(a: *const u8, b: *const u8, n: usize) -> i32 { + // INT32: %[[TEMP:.+]] = tail call i32 @memcmp(ptr %a, ptr %b, {{i32|i64}} %n) + // INT32-NOT: sext + // INT32: ret i32 %[[TEMP]] + + // INT16: %[[TEMP1:.+]] = tail call i16 @memcmp(ptr %a, ptr %b, i16 %n) + // INT16: %[[TEMP2:.+]] = sext i16 %[[TEMP1]] to i32 + // INT16: ret i32 %[[TEMP2]] + compare_bytes(a, b, n) +} + +// Ensure that, even though there's an `sext` emitted by the intrinsic, +// that doesn't end up pessiming checks against zero. +#[no_mangle] +// CHECK-LABEL: @bytes_eq( +pub unsafe fn bytes_eq(a: *const u8, b: *const u8, n: usize) -> bool { + // CHECK: call {{.+}} @{{bcmp|memcmp}}(ptr %a, ptr %b, {{i16|i32|i64}} %n) + // CHECK-NOT: sext + // INT32: icmp eq i32 + // INT16: icmp eq i16 + compare_bytes(a, b, n) == 0_i32 +} diff --git a/tests/codegen/intrinsics/mask.rs b/tests/codegen/intrinsics/mask.rs index 8f93da2e5..82131c558 100644 --- a/tests/codegen/intrinsics/mask.rs +++ b/tests/codegen/intrinsics/mask.rs @@ -7,6 +7,6 @@ #[no_mangle] pub fn mask_ptr(ptr: *const u16, mask: usize) -> *const u16 { // CHECK: call - // CHECK-SAME: @llvm.ptrmask.{{p0|p0i8}}.[[WORD]]({{ptr|i8\*}} {{%ptr|%1}}, [[WORD]] %mask) + // CHECK-SAME: @llvm.ptrmask.{{p0|p0i8}}.[[WORD]](ptr {{%ptr|%1}}, [[WORD]] %mask) core::intrinsics::ptr_mask(ptr, mask) } diff --git a/tests/codegen/intrinsics/nontemporal.rs b/tests/codegen/intrinsics/nontemporal.rs index d8ee29452..dc020c121 100644 --- a/tests/codegen/intrinsics/nontemporal.rs +++ b/tests/codegen/intrinsics/nontemporal.rs @@ -6,7 +6,7 @@ #[no_mangle] pub fn a(a: &mut u32, b: u32) { // CHECK-LABEL: define{{.*}}void @a - // CHECK: store i32 %b, {{i32\*|ptr}} %a, align 4, !nontemporal + // CHECK: store i32 %b, ptr %a, align 4, !nontemporal unsafe { std::intrinsics::nontemporal_store(a, b); } diff --git a/tests/codegen/intrinsics/offset.rs b/tests/codegen/intrinsics/offset.rs index 7fc4f4498..542bacf99 100644 --- a/tests/codegen/intrinsics/offset.rs +++ b/tests/codegen/intrinsics/offset.rs @@ -1,5 +1,4 @@ // compile-flags: -O -C no-prepopulate-passes -// min-llvm-version: 15.0 (because we're using opaque pointers) #![crate_type = "lib"] #![feature(core_intrinsics)] diff --git a/tests/codegen/intrinsics/transmute-niched.rs b/tests/codegen/intrinsics/transmute-niched.rs index 69e9b1d12..e9c8d803c 100644 --- a/tests/codegen/intrinsics/transmute-niched.rs +++ b/tests/codegen/intrinsics/transmute-niched.rs @@ -2,7 +2,6 @@ // [OPT] compile-flags: -C opt-level=3 -C no-prepopulate-passes // [DBG] compile-flags: -C opt-level=0 -C no-prepopulate-passes // only-64bit (so I don't need to worry about usize) -// min-llvm-version: 15.0 # this test assumes `ptr`s #![crate_type = "lib"] @@ -169,16 +168,16 @@ pub unsafe fn check_bool_from_ordering(x: std::cmp::Ordering) -> bool { // CHECK-LABEL: @check_bool_to_ordering( #[no_mangle] pub unsafe fn check_bool_to_ordering(x: bool) -> std::cmp::Ordering { - // CHECK: %0 = zext i1 %x to i8 - // OPT: %1 = icmp ule i8 %0, 1 - // OPT: call void @llvm.assume(i1 %1) - // OPT: %2 = icmp uge i8 %0, -1 - // OPT: %3 = icmp ule i8 %0, 1 - // OPT: %4 = or i1 %2, %3 - // OPT: call void @llvm.assume(i1 %4) + // CHECK: %_0 = zext i1 %x to i8 + // OPT: %0 = icmp ule i8 %_0, 1 + // OPT: call void @llvm.assume(i1 %0) + // OPT: %1 = icmp uge i8 %_0, -1 + // OPT: %2 = icmp ule i8 %_0, 1 + // OPT: %3 = or i1 %1, %2 + // OPT: call void @llvm.assume(i1 %3) // DBG-NOT: icmp // DBG-NOT: assume - // CHECK: ret i8 %0 + // CHECK: ret i8 %_0 transmute(x) } diff --git a/tests/codegen/intrinsics/transmute-x64.rs b/tests/codegen/intrinsics/transmute-x64.rs index 99d258c62..19020f628 100644 --- a/tests/codegen/intrinsics/transmute-x64.rs +++ b/tests/codegen/intrinsics/transmute-x64.rs @@ -1,6 +1,5 @@ // compile-flags: -O -C no-prepopulate-passes // only-x86_64 (it's using arch-specific types) -// min-llvm-version: 15.0 # this test assumes `ptr`s #![crate_type = "lib"] @@ -11,8 +10,8 @@ use std::mem::transmute; #[no_mangle] pub unsafe fn check_sse_float_to_int(x: __m128) -> __m128i { // CHECK-NOT: alloca - // CHECK: %1 = load <4 x float>, ptr %x, align 16 - // CHECK: store <4 x float> %1, ptr %0, align 16 + // CHECK: %0 = load <4 x float>, ptr %x, align 16 + // CHECK: store <4 x float> %0, ptr %_0, align 16 transmute(x) } @@ -20,8 +19,8 @@ pub unsafe fn check_sse_float_to_int(x: __m128) -> __m128i { #[no_mangle] pub unsafe fn check_sse_pair_to_avx(x: (__m128i, __m128i)) -> __m256i { // CHECK-NOT: alloca - // CHECK: %1 = load <4 x i64>, ptr %x, align 16 - // CHECK: store <4 x i64> %1, ptr %0, align 32 + // CHECK: %0 = load <4 x i64>, ptr %x, align 16 + // CHECK: store <4 x i64> %0, ptr %_0, align 32 transmute(x) } @@ -29,7 +28,7 @@ pub unsafe fn check_sse_pair_to_avx(x: (__m128i, __m128i)) -> __m256i { #[no_mangle] pub unsafe fn check_sse_pair_from_avx(x: __m256i) -> (__m128i, __m128i) { // CHECK-NOT: alloca - // CHECK: %1 = load <4 x i64>, ptr %x, align 32 - // CHECK: store <4 x i64> %1, ptr %0, align 16 + // CHECK: %0 = load <4 x i64>, ptr %x, align 32 + // CHECK: store <4 x i64> %0, ptr %_0, align 16 transmute(x) } diff --git a/tests/codegen/intrinsics/transmute.rs b/tests/codegen/intrinsics/transmute.rs index fe4249400..e64af33ab 100644 --- a/tests/codegen/intrinsics/transmute.rs +++ b/tests/codegen/intrinsics/transmute.rs @@ -1,6 +1,5 @@ // compile-flags: -O -C no-prepopulate-passes // only-64bit (so I don't need to worry about usize) -// min-llvm-version: 15.0 # this test assumes `ptr`s #![crate_type = "lib"] #![feature(core_intrinsics)] @@ -8,8 +7,8 @@ #![feature(inline_const)] #![allow(unreachable_code)] -use std::mem::MaybeUninit; use std::intrinsics::{transmute, transmute_unchecked}; +use std::mem::MaybeUninit; // Some of these need custom MIR to not get removed by MIR optimizations. use std::intrinsics::mir::*; @@ -63,7 +62,7 @@ pub unsafe fn check_to_empty_array(x: [u32; 5]) -> [u32; 0] { // CHECK-NOT: trap // CHECK: call void @llvm.trap // CHECK-NOT: trap - mir!{ + mir! { { RET = CastTransmute(x); Return() @@ -78,7 +77,7 @@ pub unsafe fn check_from_empty_array(x: [u32; 0]) -> [u32; 5] { // CHECK-NOT: trap // CHECK: call void @llvm.trap // CHECK-NOT: trap - mir!{ + mir! { { RET = CastTransmute(x); Return() @@ -93,7 +92,7 @@ pub unsafe fn check_to_uninhabited(x: u16) { // CHECK-NOT: trap // CHECK: call void @llvm.trap // CHECK-NOT: trap - mir!{ + mir! { let temp: BigNever; { temp = CastTransmute(x); @@ -107,7 +106,7 @@ pub unsafe fn check_to_uninhabited(x: u16) { #[custom_mir(dialect = "runtime", phase = "optimized")] pub unsafe fn check_from_uninhabited(x: BigNever) -> u16 { // CHECK: ret i16 poison - mir!{ + mir! { { RET = CastTransmute(x); Return() @@ -122,9 +121,7 @@ pub unsafe fn check_intermediate_passthrough(x: u32) -> i32 { // CHECK: %[[TMP:.+]] = add i32 1, %x // CHECK: %[[RET:.+]] = add i32 %[[TMP]], 1 // CHECK: ret i32 %[[RET]] - unsafe { - transmute::<u32, i32>(1 + x) + 1 - } + unsafe { transmute::<u32, i32>(1 + x) + 1 } } // CHECK-LABEL: @check_nop_pair( @@ -134,9 +131,7 @@ pub unsafe fn check_nop_pair(x: (u8, i8)) -> (i8, u8) { // CHECK: %0 = insertvalue { i8, i8 } poison, i8 %x.0, 0 // CHECK: %1 = insertvalue { i8, i8 } %0, i8 %x.1, 1 // CHECK: ret { i8, i8 } %1 - unsafe { - transmute(x) - } + unsafe { transmute(x) } } // CHECK-LABEL: @check_to_newtype( @@ -168,9 +163,9 @@ pub unsafe fn check_aggregate_to_bool(x: Aggregate8) -> bool { // CHECK-LABEL: @check_aggregate_from_bool( #[no_mangle] pub unsafe fn check_aggregate_from_bool(x: bool) -> Aggregate8 { - // CHECK: %0 = alloca %Aggregate8, align 1 + // CHECK: %_0 = alloca %Aggregate8, align 1 // CHECK: %[[BYTE:.+]] = zext i1 %x to i8 - // CHECK: store i8 %[[BYTE]], ptr %0, align 1 + // CHECK: store i8 %[[BYTE]], ptr %_0, align 1 transmute(x) } @@ -195,8 +190,8 @@ pub unsafe fn check_byte_from_bool(x: bool) -> u8 { // CHECK-LABEL: @check_to_pair( #[no_mangle] pub unsafe fn check_to_pair(x: u64) -> Option<i32> { - // CHECK: %0 = alloca { i32, i32 }, align 4 - // CHECK: store i64 %x, ptr %0, align 4 + // CHECK: %_0 = alloca { i32, i32 }, align 4 + // CHECK: store i64 %x, ptr %_0, align 4 transmute(x) } @@ -207,11 +202,11 @@ pub unsafe fn check_from_pair(x: Option<i32>) -> u64 { // immediates so we can write using the destination alloca's alignment. const { assert!(std::mem::align_of::<Option<i32>>() == 4) }; - // CHECK: %0 = alloca i64, align 8 - // CHECK: store i32 %x.0, ptr %1, align 8 - // CHECK: store i32 %x.1, ptr %2, align 4 - // CHECK: %3 = load i64, ptr %0, align 8 - // CHECK: ret i64 %3 + // CHECK: %_0 = alloca i64, align 8 + // CHECK: store i32 %x.0, ptr %0, align 8 + // CHECK: store i32 %x.1, ptr %1, align 4 + // CHECK: %2 = load i64, ptr %_0, align 8 + // CHECK: ret i64 %2 transmute(x) } @@ -219,8 +214,8 @@ pub unsafe fn check_from_pair(x: Option<i32>) -> u64 { #[no_mangle] pub unsafe fn check_to_float(x: u32) -> f32 { // CHECK-NOT: alloca - // CHECK: %0 = bitcast i32 %x to float - // CHECK: ret float %0 + // CHECK: %_0 = bitcast i32 %x to float + // CHECK: ret float %_0 transmute(x) } @@ -228,16 +223,16 @@ pub unsafe fn check_to_float(x: u32) -> f32 { #[no_mangle] pub unsafe fn check_from_float(x: f32) -> u32 { // CHECK-NOT: alloca - // CHECK: %0 = bitcast float %x to i32 - // CHECK: ret i32 %0 + // CHECK: %_0 = bitcast float %x to i32 + // CHECK: ret i32 %_0 transmute(x) } // CHECK-LABEL: @check_to_bytes( #[no_mangle] pub unsafe fn check_to_bytes(x: u32) -> [u8; 4] { - // CHECK: %0 = alloca [4 x i8], align 1 - // CHECK: store i32 %x, ptr %0, align 1 + // CHECK: %_0 = alloca [4 x i8], align 1 + // CHECK: store i32 %x, ptr %_0, align 1 transmute(x) } @@ -253,10 +248,10 @@ pub unsafe fn check_from_bytes(x: [u8; 4]) -> u32 { // CHECK-LABEL: @check_to_aggregate( #[no_mangle] pub unsafe fn check_to_aggregate(x: u64) -> Aggregate64 { - // CHECK: %0 = alloca %Aggregate64, align 4 - // CHECK: store i64 %x, ptr %0, align 4 - // CHECK: %1 = load i64, ptr %0, align 4 - // CHECK: ret i64 %1 + // CHECK: %_0 = alloca %Aggregate64, align 4 + // CHECK: store i64 %x, ptr %_0, align 4 + // CHECK: %0 = load i64, ptr %_0, align 4 + // CHECK: ret i64 %0 transmute(x) } @@ -273,7 +268,7 @@ pub unsafe fn check_from_aggregate(x: Aggregate64) -> u64 { #[no_mangle] pub unsafe fn check_long_array_less_aligned(x: [u64; 100]) -> [u16; 400] { // CHECK-NEXT: start - // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 2 %0, ptr align 8 %x, i64 800, i1 false) + // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 2 %_0, ptr align 8 %x, i64 800, i1 false) // CHECK-NEXT: ret void transmute(x) } @@ -282,7 +277,7 @@ pub unsafe fn check_long_array_less_aligned(x: [u64; 100]) -> [u16; 400] { #[no_mangle] pub unsafe fn check_long_array_more_aligned(x: [u8; 100]) -> [u32; 25] { // CHECK-NEXT: start - // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %0, ptr align 1 %x, i64 100, i1 false) + // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 4 %_0, ptr align 1 %x, i64 100, i1 false) // CHECK-NEXT: ret void transmute(x) } @@ -301,8 +296,8 @@ pub unsafe fn check_pair_with_bool(x: (u8, bool)) -> (bool, i8) { pub unsafe fn check_float_to_pointer(x: f64) -> *const () { // CHECK-NOT: alloca // CHECK: %0 = bitcast double %x to i64 - // CHECK: %1 = inttoptr i64 %0 to ptr - // CHECK: ret ptr %1 + // CHECK: %_0 = inttoptr i64 %0 to ptr + // CHECK: ret ptr %_0 transmute(x) } @@ -311,8 +306,8 @@ pub unsafe fn check_float_to_pointer(x: f64) -> *const () { pub unsafe fn check_float_from_pointer(x: *const ()) -> f64 { // CHECK-NOT: alloca // CHECK: %0 = ptrtoint ptr %x to i64 - // CHECK: %1 = bitcast i64 %0 to double - // CHECK: ret double %1 + // CHECK: %_0 = bitcast i64 %0 to double + // CHECK: ret double %_0 transmute(x) } @@ -376,10 +371,10 @@ pub unsafe fn check_issue_110005(x: (usize, bool)) -> Option<Box<[u8]>> { // CHECK-LABEL: @check_pair_to_dst_ref( #[no_mangle] pub unsafe fn check_pair_to_dst_ref<'a>(x: (usize, usize)) -> &'a [u8] { - // CHECK: %0 = inttoptr i64 %x.0 to ptr - // CHECK: %1 = insertvalue { ptr, i64 } poison, ptr %0, 0 - // CHECK: %2 = insertvalue { ptr, i64 } %1, i64 %x.1, 1 - // CHECK: ret { ptr, i64 } %2 + // CHECK: %_0.0 = inttoptr i64 %x.0 to ptr + // CHECK: %0 = insertvalue { ptr, i64 } poison, ptr %_0.0, 0 + // CHECK: %1 = insertvalue { ptr, i64 } %0, i64 %x.1, 1 + // CHECK: ret { ptr, i64 } %1 transmute(x) } @@ -391,7 +386,7 @@ pub unsafe fn check_issue_109992(x: ()) -> [(); 1] { // CHECK: start // CHECK-NEXT: ret void - mir!{ + mir! { { RET = CastTransmute(x); Return() @@ -408,7 +403,7 @@ pub unsafe fn check_unit_to_never(x: ()) { // CHECK-NOT: trap // CHECK: call void @llvm.trap // CHECK-NOT: trap - mir!{ + mir! { let temp: ZstNever; { temp = CastTransmute(x); @@ -425,7 +420,7 @@ pub unsafe fn check_unit_from_never(x: ZstNever) -> () { // CHECK: start // CHECK-NEXT: ret void - mir!{ + mir! { { RET = CastTransmute(x); Return() @@ -457,10 +452,10 @@ pub struct HighAlignScalar(u8); // CHECK-LABEL: @check_to_overalign( #[no_mangle] pub unsafe fn check_to_overalign(x: u64) -> HighAlignScalar { - // CHECK: %0 = alloca %HighAlignScalar, align 8 - // CHECK: store i64 %x, ptr %0, align 8 - // CHECK: %1 = load i64, ptr %0, align 8 - // CHECK: ret i64 %1 + // CHECK: %_0 = alloca %HighAlignScalar, align 8 + // CHECK: store i64 %x, ptr %_0, align 8 + // CHECK: %0 = load i64, ptr %_0, align 8 + // CHECK: ret i64 %0 transmute(x) } |