diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-01 08:53:05 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-01 08:53:05 +0200 |
| commit | c471e0715666bfa0184030af96ae7b45e81aa0b7 (patch) | |
| tree | ce0decf5674e2311b111f091b7c491f03da064de | |
| parent | f92a6c41e644d6222be77b20396daec5e77661f3 (diff) | |
| parent | ac670721c90985af11ddfe7d00b6ffcb8b5d226d (diff) | |
Rollup merge of #126923 - workingjubilee:regression-tests-for-simd-invalid-bitcast, r=calebzulawski
test: dont optimize to invalid bitcasts Regression tests to prevent regressing.
| -rw-r--r-- | tests/ui/simd/dont-invalid-bitcast-masks.rs | 17 | ||||
| -rw-r--r-- | tests/ui/simd/dont-invalid-bitcast-x86_64.rs | 27 |
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/ui/simd/dont-invalid-bitcast-masks.rs b/tests/ui/simd/dont-invalid-bitcast-masks.rs new file mode 100644 index 00000000000..3d8376207cd --- /dev/null +++ b/tests/ui/simd/dont-invalid-bitcast-masks.rs @@ -0,0 +1,17 @@ +//@ build-pass +//@ compile-flags: -Copt-level=3 + +// regression test for https://github.com/rust-lang/rust/issues/110722 +// in --release we were optimizing to invalid bitcasts, due to a combination of MIR inlining and +// mostly bad repr(simd) lowering which prevented even basic splats from working +#![crate_type = "rlib"] +#![feature(portable_simd)] +use std::simd::*; +use std::simd::num::*; + +pub unsafe fn mask_to_array(mask: u8) -> [i32; 8] { + let mut output = [0; 8]; + let m = masksizex8::from_bitmask(mask as _); + output.copy_from_slice(&m.to_int().cast::<i32>().to_array()); + output +} diff --git a/tests/ui/simd/dont-invalid-bitcast-x86_64.rs b/tests/ui/simd/dont-invalid-bitcast-x86_64.rs new file mode 100644 index 00000000000..e6e435bcfc9 --- /dev/null +++ b/tests/ui/simd/dont-invalid-bitcast-x86_64.rs @@ -0,0 +1,27 @@ +//@ build-pass +//@ compile-flags: -Copt-level=3 +//@ only-x86_64 +// ignore-tidy-linelength + +// regression test for https://github.com/rust-lang/rust/issues/110707 +// in --release we were optimizing to invalid bitcasts, due to a combination of MIR inlining and +// mostly bad repr(simd) lowering which prevented even basic splats from working + +#![crate_type = "rlib"] +#![feature(portable_simd)] +use std::simd::*; +use std::arch::x86_64::*; + +#[target_feature(enable = "sse4.1")] +pub unsafe fn fast_round_sse(i: f32x8) -> f32x8 { + let a = i.to_array(); + let [low, high]: [[f32; 4]; 2] = + unsafe { std::mem::transmute::<[f32; 8], [[f32; 4]; 2]>(a) }; + + let low = f32x4::from(_mm_round_ps::<{_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC}>(f32x4::from_array(low).into())); + let high = f32x4::from(_mm_round_ps::<{_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC}>(f32x4::from_array(high).into())); + + let a: [f32; 8] = + unsafe { std::mem::transmute::<[[f32; 4]; 2], [f32; 8]>([low.to_array(), high.to_array()]) }; + f32x8::from_array(a) +} |
