Closed
Description
opened on Mar 16, 2024
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
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: MIR optimizationsCategory: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to performance of generated code.
Activity