-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Discriminant update fails to optimize #122600
Comments
lol, looks like this optimizes with |
Replacing
Presumably some issue with MIR inlining; #[inline(never)]
fn unreachable2() -> ! {
unsafe { unreachable_unchecked() }
}
#[no_mangle]
unsafe fn init(s: *mut State) {
let State::A(v) = read(s) else { unreachable2() };
write(s, State::B(v));
} produces the optimal code |
The problem is not MIR inlining per se. I think this is the problem @DianQK was trying to fix in #122282; if you write your own |
Upstream issue: llvm/llvm-project#85560 @rustbot claim |
@rustbot label +llvm-fixed-upstream |
Confirmed fixed by #127513, needs codegen test. |
…lacrum Add test for updating enum discriminant through pointer Closes rust-lang#122600
…lacrum Add test for updating enum discriminant through pointer Closes rust-lang#122600
…lacrum Add test for updating enum discriminant through pointer Closes rust-lang#122600
…lacrum Add test for updating enum discriminant through pointer Closes rust-lang#122600
…lacrum Add test for updating enum discriminant through pointer Closes rust-lang#122600
Rollup merge of rust-lang#128500 - clubby789:122600-test, r=Mark-Simulacrum Add test for updating enum discriminant through pointer Closes rust-lang#122600
The following code should optimize to a single store of the new discriminant, but doesn't (Godbolt).
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
:The text was updated successfully, but these errors were encountered: