From 5acfe772fa811e08046ea849e1b4d84b11e60c34 Mon Sep 17 00:00:00 2001 From: DianQK Date: Sat, 6 Apr 2024 22:16:10 +0800 Subject: [PATCH] Add the test case for #122805 --- tests/codegen/issues/issue-122805.rs | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/codegen/issues/issue-122805.rs diff --git a/tests/codegen/issues/issue-122805.rs b/tests/codegen/issues/issue-122805.rs new file mode 100644 index 00000000000..3bfffcd4a96 --- /dev/null +++ b/tests/codegen/issues/issue-122805.rs @@ -0,0 +1,35 @@ +//@ compile-flags: -O +//@ min-llvm-version: 18.1.3 + +#![crate_type = "lib"] +#![no_std] + +// The code is from https://github.com/rust-lang/rust/issues/122805. +// Ensure we do not generate the shufflevector instruction +// to avoid complicating the code. +// CHECK-LABEL: define{{.*}}void @convert( +// CHECK-NOT: shufflevector +// CHECK: insertelement <8 x i16> +// CHECK-NEXT: insertelement <8 x i16> +// CHECK-NEXT: insertelement <8 x i16> +// CHECK-NEXT: insertelement <8 x i16> +// CHECK-NEXT: insertelement <8 x i16> +// CHECK-NEXT: insertelement <8 x i16> +// CHECK-NEXT: insertelement <8 x i16> +// CHECK-NEXT: insertelement <8 x i16> +// CHECK-NEXT: store <8 x i16> +// CHECK-NEXT: ret void +#[no_mangle] +pub fn convert(value: [u16; 8]) -> [u8; 16] { + let addr16 = [ + value[0].to_be(), + value[1].to_be(), + value[2].to_be(), + value[3].to_be(), + value[4].to_be(), + value[5].to_be(), + value[6].to_be(), + value[7].to_be(), + ]; + unsafe { core::mem::transmute::<_, [u8; 16]>(addr16) } +}