diff options
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/avr/avr-func-addrspace.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/cast-optimized.rs | 35 | ||||
| -rw-r--r-- | tests/codegen/clone-shims.rs | 15 | ||||
| -rw-r--r-- | tests/codegen/emcripten-catch-unwind.rs | 2 | ||||
| -rw-r--r-- | tests/codegen/float/f128.rs | 11 | ||||
| -rw-r--r-- | tests/codegen/float/f16.rs | 11 | ||||
| -rw-r--r-- | tests/codegen/generic-debug.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/issues/issue-32031.rs | 10 | ||||
| -rw-r--r-- | tests/codegen/issues/issue-58881.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/mainsubprogram.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/mainsubprogramstart.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/nounwind.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/option-as-slice.rs | 35 | ||||
| -rw-r--r-- | tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs | 1 | ||||
| -rw-r--r-- | tests/codegen/try_identity.rs | 34 | ||||
| -rw-r--r-- | tests/codegen/union-abi.rs | 10 |
17 files changed, 123 insertions, 48 deletions
diff --git a/tests/codegen/avr/avr-func-addrspace.rs b/tests/codegen/avr/avr-func-addrspace.rs index 70834707564..7f9a7e6e811 100644 --- a/tests/codegen/avr/avr-func-addrspace.rs +++ b/tests/codegen/avr/avr-func-addrspace.rs @@ -17,6 +17,7 @@ pub trait Sized {} #[lang = "copy"] pub trait Copy {} +impl<T: ?Sized> Copy for *const T {} #[lang = "receiver"] pub trait Receiver {} #[lang = "tuple_trait"] diff --git a/tests/codegen/cast-optimized.rs b/tests/codegen/cast-optimized.rs new file mode 100644 index 00000000000..313b2b4f0d6 --- /dev/null +++ b/tests/codegen/cast-optimized.rs @@ -0,0 +1,35 @@ +//@ compile-flags: -O -Z merge-functions=disabled +#![crate_type = "lib"] + +// This tests that LLVM can optimize based on the niches in the source or +// destination types for casts. + +// CHECK-LABEL: @u32_index +#[no_mangle] +pub fn u32_index(c: u32) -> [bool; 22] { + let mut array = [false; 22]; + + let index = 32 - c.leading_zeros(); + + // CHECK: call core::panicking::panic + array[index as usize] = true; + + array +} + +// CHECK-LABEL: @char_as_u32_index +#[no_mangle] +pub fn char_as_u32_index(c: char) -> [bool; 22] { + // CHECK: %[[B:.+]] = icmp ult i32 %c, 1114112 + // CHECK: call void @llvm.assume(i1 %[[B]]) + let c = c as u32; + + let mut array = [false; 22]; + + let index = 32 - c.leading_zeros(); + + // CHECK-NOT: call core::panicking::panic + array[index as usize] = true; + + array +} diff --git a/tests/codegen/clone-shims.rs b/tests/codegen/clone-shims.rs new file mode 100644 index 00000000000..06c959f9ee7 --- /dev/null +++ b/tests/codegen/clone-shims.rs @@ -0,0 +1,15 @@ +// Clone shims for aggregates are generated by just calling the Clone shims for all their members. +// Those calls generate a lot of unnecessary IR if the members are Copy. This test ensures that we +// optimize away those inner calls without needing to inline them. + +//@ compile-flags: -Cno-prepopulate-passes -Csymbol-mangling-version=v0 -Zinline-mir=no +#![crate_type = "lib"] + +pub type Test = (i32, i32, *const i32); +pub static TEST: fn(&Test) -> Test = <Test as core::clone::Clone>::clone; + +// CHECK-NOT: call <i32 as core::clone::Clone>::clone +// CHECK-NOT: call <*const i32 as core::clone::Clone>::clone +// CHECK: ; <(i32, i32, *const i32) as core::clone::Clone>::clone +// CHECK-NOT: call <i32 as core::clone::Clone>::clone +// CHECK-NOT: call <*const i32 as core::clone::Clone>::clone diff --git a/tests/codegen/emcripten-catch-unwind.rs b/tests/codegen/emcripten-catch-unwind.rs index 6cda8c6799f..35444db9558 100644 --- a/tests/codegen/emcripten-catch-unwind.rs +++ b/tests/codegen/emcripten-catch-unwind.rs @@ -16,6 +16,8 @@ trait Freeze {} #[lang = "copy"] trait Copy {} +impl<T> Copy for *mut T {} + #[rustc_intrinsic] fn size_of<T>() -> usize { loop {} diff --git a/tests/codegen/float/f128.rs b/tests/codegen/float/f128.rs index 32c5be1ec65..80b572fbbc9 100644 --- a/tests/codegen/float/f128.rs +++ b/tests/codegen/float/f128.rs @@ -1,3 +1,8 @@ +// 32-bit x86 returns `f32` and `f64` differently to avoid the x87 stack. +//@ revisions: x86 other +//@[x86] only-x86 +//@[other] ignore-x86 + // Verify that our intrinsics generate the correct LLVM calls for f128 #![crate_type = "lib"] @@ -138,14 +143,16 @@ pub fn f128_as_f16(a: f128) -> f16 { a as f16 } -// CHECK-LABEL: float @f128_as_f32( +// other-LABEL: float @f128_as_f32( +// x86-LABEL: i32 @f128_as_f32( #[no_mangle] pub fn f128_as_f32(a: f128) -> f32 { // CHECK: fptrunc fp128 %{{.+}} to float a as f32 } -// CHECK-LABEL: double @f128_as_f64( +// other-LABEL: double @f128_as_f64( +// x86-LABEL: void @f128_as_f64( #[no_mangle] pub fn f128_as_f64(a: f128) -> f64 { // CHECK: fptrunc fp128 %{{.+}} to double diff --git a/tests/codegen/float/f16.rs b/tests/codegen/float/f16.rs index 96daac869c2..2910d7d3e92 100644 --- a/tests/codegen/float/f16.rs +++ b/tests/codegen/float/f16.rs @@ -1,3 +1,8 @@ +// 32-bit x86 returns `f32` and `f64` differently to avoid the x87 stack. +//@ revisions: x86 other +//@[x86] only-x86 +//@[other] ignore-x86 + // Verify that our intrinsics generate the correct LLVM calls for f16 #![crate_type = "lib"] @@ -140,14 +145,16 @@ pub fn f16_as_self(a: f16) -> f16 { a as f16 } -// CHECK-LABEL: float @f16_as_f32( +// other-LABEL: float @f16_as_f32( +// x86-LABEL: i32 @f16_as_f32( #[no_mangle] pub fn f16_as_f32(a: f16) -> f32 { // CHECK: fpext half %{{.+}} to float a as f32 } -// CHECK-LABEL: double @f16_as_f64( +// other-LABEL: double @f16_as_f64( +// x86-LABEL: void @f16_as_f64( #[no_mangle] pub fn f16_as_f64(a: f16) -> f64 { // CHECK: fpext half %{{.+}} to double diff --git a/tests/codegen/generic-debug.rs b/tests/codegen/generic-debug.rs index 3423abe7187..0ad0b074657 100644 --- a/tests/codegen/generic-debug.rs +++ b/tests/codegen/generic-debug.rs @@ -1,4 +1,3 @@ -//@ ignore-windows //@ ignore-wasi wasi codegens the main symbol differently //@ compile-flags: -g -C no-prepopulate-passes diff --git a/tests/codegen/issues/issue-32031.rs b/tests/codegen/issues/issue-32031.rs index 9693c414a67..4d6895166f1 100644 --- a/tests/codegen/issues/issue-32031.rs +++ b/tests/codegen/issues/issue-32031.rs @@ -1,11 +1,16 @@ //@ compile-flags: -C no-prepopulate-passes -Copt-level=0 +// 32-bit x86 returns `f32` and `f64` differently to avoid the x87 stack. +//@ revisions: x86 other +//@[x86] only-x86 +//@[other] ignore-x86 #![crate_type = "lib"] #[no_mangle] pub struct F32(f32); -// CHECK: define{{.*}}float @add_newtype_f32(float %a, float %b) +// other: define{{.*}}float @add_newtype_f32(float %a, float %b) +// x86: define{{.*}}i32 @add_newtype_f32(float %a, float %b) #[inline(never)] #[no_mangle] pub fn add_newtype_f32(a: F32, b: F32) -> F32 { @@ -15,7 +20,8 @@ pub fn add_newtype_f32(a: F32, b: F32) -> F32 { #[no_mangle] pub struct F64(f64); -// CHECK: define{{.*}}double @add_newtype_f64(double %a, double %b) +// other: define{{.*}}double @add_newtype_f64(double %a, double %b) +// x86: define{{.*}}void @add_newtype_f64(ptr{{.*}}sret([8 x i8]){{.*}}%_0, double %a, double %b) #[inline(never)] #[no_mangle] pub fn add_newtype_f64(a: F64, b: F64) -> F64 { diff --git a/tests/codegen/issues/issue-58881.rs b/tests/codegen/issues/issue-58881.rs index 759e3b70baa..ba6285f3972 100644 --- a/tests/codegen/issues/issue-58881.rs +++ b/tests/codegen/issues/issue-58881.rs @@ -1,7 +1,6 @@ //@ compile-flags: -C no-prepopulate-passes -Copt-level=0 // //@ only-x86_64 -//@ ignore-windows #![crate_type = "lib"] diff --git a/tests/codegen/mainsubprogram.rs b/tests/codegen/mainsubprogram.rs index 12b24c90229..ce3fe3c8608 100644 --- a/tests/codegen/mainsubprogram.rs +++ b/tests/codegen/mainsubprogram.rs @@ -1,7 +1,6 @@ // This test depends on a patch that was committed to upstream LLVM // before 4.0, formerly backported to the Rust LLVM fork. -//@ ignore-windows //@ ignore-apple //@ ignore-wasi diff --git a/tests/codegen/mainsubprogramstart.rs b/tests/codegen/mainsubprogramstart.rs index 20741791db5..0bcb311644d 100644 --- a/tests/codegen/mainsubprogramstart.rs +++ b/tests/codegen/mainsubprogramstart.rs @@ -1,4 +1,3 @@ -//@ ignore-windows //@ ignore-apple //@ ignore-wasi wasi codegens the main symbol differently diff --git a/tests/codegen/nounwind.rs b/tests/codegen/nounwind.rs index 464bc2535c2..c910644458a 100644 --- a/tests/codegen/nounwind.rs +++ b/tests/codegen/nounwind.rs @@ -1,6 +1,5 @@ //@ aux-build:nounwind.rs //@ compile-flags: -C no-prepopulate-passes -C panic=abort -C metadata=a -//@ ignore-windows //@ ignore-android #![crate_type = "lib"] diff --git a/tests/codegen/option-as-slice.rs b/tests/codegen/option-as-slice.rs index 65637a2495d..cfa479aa4b2 100644 --- a/tests/codegen/option-as-slice.rs +++ b/tests/codegen/option-as-slice.rs @@ -14,6 +14,14 @@ pub fn u64_opt_as_slice(o: &Option<u64>) -> &[u64] { // CHECK-NOT: br // CHECK-NOT: switch // CHECK-NOT: icmp + // CHECK: %[[LEN:.+]] = load i64,{{.+}} !range ![[META_U64:.+]], !noundef + // CHECK-NOT: select + // CHECK-NOT: br + // CHECK-NOT: switch + // CHECK-NOT: icmp + // CHECK: %[[T0:.+]] = insertvalue { ptr, i64 } poison, ptr %{{.+}}, 0 + // CHECK-NEXT: %[[T1:.+]] = insertvalue { ptr, i64 } %[[T0]], i64 %[[LEN]], 1 + // CHECK-NEXT: ret { ptr, i64 } %[[T1]] o.as_slice() } @@ -25,10 +33,35 @@ pub fn nonzero_u64_opt_as_slice(o: &Option<NonZero<u64>>) -> &[NonZero<u64>] { // CHECK-NOT: switch // CHECK-NOT: icmp // CHECK: %[[NZ:.+]] = icmp ne i64 %{{.+}}, 0 - // CHECK-NEXT: zext i1 %[[NZ]] to i64 + // CHECK-NEXT: %[[LEN:.+]] = zext i1 %[[NZ]] to i64 // CHECK-NOT: select // CHECK-NOT: br // CHECK-NOT: switch // CHECK-NOT: icmp + // CHECK: %[[T0:.+]] = insertvalue { ptr, i64 } poison, ptr %o, 0 + // CHECK-NEXT: %[[T1:.+]] = insertvalue { ptr, i64 } %[[T0]], i64 %[[LEN]], 1 + // CHECK-NEXT: ret { ptr, i64 } %[[T1]] o.as_slice() } + +// CHECK-LABEL: @u8_opt_as_slice +#[no_mangle] +pub fn u8_opt_as_slice(o: &Option<u8>) -> &[u8] { + // CHECK-NOT: select + // CHECK-NOT: br + // CHECK-NOT: switch + // CHECK-NOT: icmp + // CHECK: %[[TAG:.+]] = load i8,{{.+}} !range ![[META_U8:.+]], !noundef + // CHECK: %[[LEN:.+]] = zext{{.*}} i8 %[[TAG]] to i64 + // CHECK-NOT: select + // CHECK-NOT: br + // CHECK-NOT: switch + // CHECK-NOT: icmp + // CHECK: %[[T0:.+]] = insertvalue { ptr, i64 } poison, ptr %{{.+}}, 0 + // CHECK-NEXT: %[[T1:.+]] = insertvalue { ptr, i64 } %[[T0]], i64 %[[LEN]], 1 + // CHECK-NEXT: ret { ptr, i64 } %[[T1]] + o.as_slice() +} + +// CHECK: ![[META_U64]] = !{i64 0, i64 2} +// CHECK: ![[META_U8]] = !{i8 0, i8 2} diff --git a/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs b/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs index ed0af90aaaf..520192b5d59 100644 --- a/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs +++ b/tests/codegen/riscv-abi/riscv64-lp64-lp64f-lp64d-abi.rs @@ -18,6 +18,7 @@ impl Copy for i64 {} impl Copy for u64 {} impl Copy for f32 {} impl Copy for f64 {} +impl<T> Copy for *mut T {} // CHECK: define void @f_void() #[no_mangle] diff --git a/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs b/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs index fc4d570dc2e..c1967e55e75 100644 --- a/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs +++ b/tests/codegen/sanitizer/kcfi/emit-type-metadata-trait-objects.rs @@ -15,6 +15,7 @@ trait Sized {} #[lang = "copy"] trait Copy {} +impl<T: ?Sized> Copy for &T {} #[lang = "receiver"] trait Receiver {} #[lang = "dispatch_from_dyn"] diff --git a/tests/codegen/try_identity.rs b/tests/codegen/try_identity.rs deleted file mode 100644 index 6a3a8a06e82..00000000000 --- a/tests/codegen/try_identity.rs +++ /dev/null @@ -1,34 +0,0 @@ -//@ compile-flags: -C no-prepopulate-passes -O -Z mir-opt-level=3 -Zunsound-mir-opts - -// Ensure that `x?` has no overhead on `Result<T, E>` due to identity `match`es in lowering. -// This requires inlining to trigger the MIR optimizations in `SimplifyArmIdentity`. - -#![crate_type = "lib"] - -type R = Result<u64, i32>; - -// This was written to the `?` from `try_trait`, but `try_trait_v2` uses a different structure, -// so the relevant desugar is copied inline in order to keep the test testing the same thing. -// FIXME(#85133): while this might be useful for `r#try!`, it would be nice to have a MIR -// optimization that picks up the `?` desugaring, as `SimplifyArmIdentity` does not. -#[no_mangle] -pub fn try_identity(x: R) -> R { - // CHECK: start: - // FIXME(JakobDegen): Broken by deaggregation change CHECK-NOT\: br {{.*}} - // CHECK ret void - let y = match into_result(x) { - Err(e) => return from_error(From::from(e)), - Ok(v) => v, - }; - Ok(y) -} - -#[inline] -fn into_result<T, E>(r: Result<T, E>) -> Result<T, E> { - r -} - -#[inline] -fn from_error<T, E>(e: E) -> Result<T, E> { - Err(e) -} diff --git a/tests/codegen/union-abi.rs b/tests/codegen/union-abi.rs index 9e02fa9ff35..08015014456 100644 --- a/tests/codegen/union-abi.rs +++ b/tests/codegen/union-abi.rs @@ -1,5 +1,9 @@ //@ ignore-emscripten vectors passed directly //@ compile-flags: -O -C no-prepopulate-passes +// 32-bit x86 returns `f32` differently to avoid the x87 stack. +//@ revisions: x86 other +//@[x86] only-x86 +//@[other] ignore-x86 // This test that using union forward the abi of the inner type, as // discussed in #54668 @@ -67,7 +71,8 @@ pub union UnionF32 { a: f32, } -// CHECK: define {{(dso_local )?}}float @test_UnionF32(float %_1) +// other: define {{(dso_local )?}}float @test_UnionF32(float %_1) +// x86: define {{(dso_local )?}}i32 @test_UnionF32(float %_1) #[no_mangle] pub fn test_UnionF32(_: UnionF32) -> UnionF32 { loop {} @@ -78,7 +83,8 @@ pub union UnionF32F32 { b: f32, } -// CHECK: define {{(dso_local )?}}float @test_UnionF32F32(float %_1) +// other: define {{(dso_local )?}}float @test_UnionF32F32(float %_1) +// x86: define {{(dso_local )?}}i32 @test_UnionF32F32(float %_1) #[no_mangle] pub fn test_UnionF32F32(_: UnionF32F32) -> UnionF32F32 { loop {} |
