Skip to content

Commit 5a0032c

Browse files
tests: simplify dont-shufflevector-bswaps test
First, give it an appropriate name instead of "issue 122805": it is about not generating shufflevector when a byteswap would do, so we call it dont-shufflevector-bswaps now. Second, explicitly set -Copt-level=2 instead of using -O Third, remove unnecessary cruft: we only need to reason about the shufflevector instruction and the bswap intrinsic.
1 parent 43ca9d1 commit 5a0032c

File tree

2 files changed

+36
-58
lines changed

2 files changed

+36
-58
lines changed
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//@ revisions: OPT2 OPT3
2+
//@ [OPT2] compile-flags: -Copt-level=2
3+
//@ [OPT3] compile-flags: -C opt-level=3
4+
//@ min-llvm-version: 18.1.3
5+
6+
#![crate_type = "lib"]
7+
#![no_std]
8+
9+
// The code is from https://github.com/rust-lang/rust/issues/122805.
10+
// Ensure we do not generate the shufflevector instruction
11+
// to avoid complicating the code.
12+
// CHECK-LABEL: define{{.*}}void @convert(
13+
// CHECK-NOT: shufflevector
14+
// On higher opt levels, this should just be a bswap:
15+
// OPT3: load <8 x i16>
16+
// OPT3-NEXT: call <8 x i16> @llvm.bswap
17+
// OPT3-NEXT: store <8 x i16>
18+
// OPT3-NEXT: ret void
19+
#[no_mangle]
20+
pub fn convert(value: [u16; 8]) -> [u8; 16] {
21+
#[cfg(target_endian = "little")]
22+
let bswap = u16::to_be;
23+
#[cfg(target_endian = "big")]
24+
let bswap = u16::to_le;
25+
let addr16 = [
26+
bswap(value[0]),
27+
bswap(value[1]),
28+
bswap(value[2]),
29+
bswap(value[3]),
30+
bswap(value[4]),
31+
bswap(value[5]),
32+
bswap(value[6]),
33+
bswap(value[7]),
34+
];
35+
unsafe { core::mem::transmute::<_, [u8; 16]>(addr16) }
36+
}

tests/codegen/issues/issue-122805.rs

-58
This file was deleted.

0 commit comments

Comments
 (0)