- Notifications
You must be signed in to change notification settings - Fork 13.8k
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-mir-optArea: MIR optimizationsArea: MIR optimizationsC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.
Description
The following code should optimize to a single store of the new discriminant, but doesn't (Godbolt).
enum State { A([u8; 753]), B([u8; 753]), //C, } unsafe fn update(s: *mut State) { let S::A(v) = s.read() else { unreachable_unchecked() }; s.write(S::B(v)); }
Instead, LLVM copies the value to the stack, copies it again and then writes it back. Interestingly, LLVM optimizes this correctly if a third state without value is added.
Meta
rustc --version --verbose
:
rustc 1.78.0-nightly (c67326b06 2024-03-15) binary: rustc commit-hash: c67326b063bd27ed04f306ba2e372cd92e0a8751 commit-date: 2024-03-15 host: x86_64-unknown-linux-gnu release: 1.78.0-nightly LLVM version: 18.1.0
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-mir-optArea: MIR optimizationsArea: MIR optimizationsC-bugCategory: This is a bug.Category: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.