Skip to content

Add codegen test for array comparision opt #82459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/test/assembly/62531-array-cmp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Ensure the asm for array comparisons is properly optimized on x86.

// min-llvm-version: 11
// assembly-output: emit-asm
// compile-flags: -C opt-level=2
// only-x86_64

#![crate_type = "lib"]

// CHECK-LABEL: compare
// CHECK: movb $1, %al
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should CHECK-NEXT here. There are a number of plausible ways to generate code for this that would result in these two instructions somewhere, but not necessarily in just these two instructions.

// 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]
}
}