-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityllvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixesregression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Description
Code
I tried this code:
// Taken from `Ipv6Addr::new`
pub fn convert1(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 { std::mem::transmute::<_, [u8; 16]>(addr16) }
}
pub fn convert2(value: [u16; 8]) -> [u8; 16] {
let addr16 = value.map(|val| val.to_be());
unsafe { std::mem::transmute::<_, [u8; 16]>(addr16) }
}
I expected to see this happen: these two pieces of code produced the same assembly
Instead, this happened: the first version generates worse code https://rust.godbolt.org/z/qrz7Pn1a7
Version it worked on
It most recently worked on: 1.76
Version with regression
rustc --version --verbose
:
rustc 1.78.0-beta.1 (efd9d2df1 2024-03-18)
binary: rustc
commit-hash: efd9d2df12b5e17fac0b4d0fb89f612ecd79f259
commit-date: 2024-03-18
host: x86_64-unknown-linux-gnu
release: 1.78.0-beta.1
LLVM version: 18.1.2
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityllvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesIssue expected to be fixed by the next major LLVM upgrade, or backported fixesregression-untriagedUntriaged performance or correctness regression.Untriaged performance or correctness regression.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
dianqk commentedon Mar 21, 2024
The main branch of LLVM may have fixed this issue: https://llvm.godbolt.org/z/WzM1dvrTb.
workingjubilee commentedon Mar 21, 2024
This seems to become much better if one uses infallible destructuring, like so:https://rust.godbolt.org/z/csraMobE8Whoops, compared against 1.76, my mistake.
apiraino commentedon Mar 21, 2024
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium
dianqk commentedon Mar 21, 2024
I have bisected to llvm/llvm-project@1e828f8 (llvm/llvm-project#82279). But I'm not sure if this match the backport rules.
I have submitted a backport request, but it may be rejected.
dianqk commentedon Mar 24, 2024
@rustbot label llvm-fixed-upstream
Add the test case for rust-lang#122805
Auto merge of rust-lang#123555 - DianQK:update-llvm-18, r=cuviper
Add the test case for rust-lang#122805
Auto merge of rust-lang#123555 - DianQK:update-llvm-18, r=cuviper
scalar_copy_backend_type
optimization attempt #123185