Closed
Description
The following functions ought to be equivalent:
use core::cmp::Ordering;
pub fn test1(call: fn() -> Ordering) -> i32 {
match call() {
Ordering::Less => -1,
Ordering::Equal => 0,
Ordering::Greater => 1,
}
}
pub fn test2(call: fn() -> Ordering) -> i32 {
call() as i32
}
but compile to the following x86_64 assembly on play.rust-lang.org:
playground::test1:
pushq %rax
callq *%rdi
incb %al
movzbl %al, %eax
decl %eax
popq %rcx
retq
playground::test2:
pushq %rax
callq *%rdi
movsbl %al, %eax
popq %rcx
retq
for both stable (1.66.0) and nightly (1.68.0-nightly 2023-01-03 c757267).
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: MIR optimizationsCategory: This is a bug.Issue: Problems and improvements with respect to performance of generated code.Relevant to the compiler team, which will review and decide on the PR/issue.