From 4b7466c43899529dfd66a1a1e77369bd1f9e2d23 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 00:21:06 +0000 Subject: [PATCH 1/2] Add codegen test for array comparision opt --- tests/assembly/62531-array-cmp.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/assembly/62531-array-cmp.rs diff --git a/tests/assembly/62531-array-cmp.rs b/tests/assembly/62531-array-cmp.rs new file mode 100644 index 0000000000000..beb19d5f8a6ab --- /dev/null +++ b/tests/assembly/62531-array-cmp.rs @@ -0,0 +1,21 @@ +// Ensure the asm for array comparisons is properly optimized on x86. + +//@ min-llvm-version: 12 +//@ assembly-output: emit-asm +//@ compile-flags: -C opt-level=2 +//@ only-x86_64 + +#![crate_type = "lib"] + +// CHECK-LABEL: compare +// CHECK: movb $1, %al +// CHECK-NEXT: retq +#[no_mangle] +pub fn compare() -> bool { + let bytes = 12.5f32.to_ne_bytes(); + bytes == if cfg!(target_endian = "big") { + [0x41, 0x48, 0x00, 0x00] + } else { + [0x00, 0x00, 0x48, 0x41] + } +} From 422de3581a8f21e7b967080ff1fb84e755b06c4a Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 15:51:24 +0000 Subject: [PATCH 2/2] make it into an IR test --- .../62531-array-cmp.rs => codegen/array-cmp.rs} | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) rename tests/{assembly/62531-array-cmp.rs => codegen/array-cmp.rs} (56%) diff --git a/tests/assembly/62531-array-cmp.rs b/tests/codegen/array-cmp.rs similarity index 56% rename from tests/assembly/62531-array-cmp.rs rename to tests/codegen/array-cmp.rs index beb19d5f8a6ab..8c6e6623146b4 100644 --- a/tests/assembly/62531-array-cmp.rs +++ b/tests/codegen/array-cmp.rs @@ -1,15 +1,11 @@ -// Ensure the asm for array comparisons is properly optimized on x86. +// Ensure the asm for array comparisons is properly optimized. -//@ min-llvm-version: 12 -//@ assembly-output: emit-asm //@ compile-flags: -C opt-level=2 -//@ only-x86_64 #![crate_type = "lib"] -// CHECK-LABEL: compare -// CHECK: movb $1, %al -// CHECK-NEXT: retq +// CHECK-LABEL: @compare +// CHECK-NEXT: ret i1 true #[no_mangle] pub fn compare() -> bool { let bytes = 12.5f32.to_ne_bytes();