-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
[MIR] non-zeroing drop #33622
[MIR] non-zeroing drop #33622
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
After this MIR pass, will all MIR drops be unconditional? (That is, any conditional drops will be guarded by explicit conditional branching in the MIR.) |
Right. |
Passes |
cc #5016 This is awesome! Do we have benchmarks? Will functions like |
Performance numbers: stage1 MIR librustc (old):
stage2 MIR librustc:
|
stage 3 MIR librustc (there was some perf issue with stage2 apparently).
Non
|
☔ The latest upstream changes (presumably #33632) made this pull request unmergeable. Please resolve the merge conflicts. |
perf after rebase:
I get the feeling that SimpifyCfg is not doing its work. |
@arielb1 What makes you think that? IOW, what do you expect it to do that doesn't happen? |
Just that there are no perf improvements over its merge. Maybe LLVM just does this by itself. |
@nikomatsakis @arielb1 I was under the impression that I would be given a chance to put up a properly revised PR of the data flow fixes (cleaning up the warnings and the commit history). I obviously can't stop people from merging this PR as is, but it would be a little irritating to me if that happened |
(In any case, I'll try to soon put up a separate PR with just the data flow fixes, that will include the relevant changes contributed by @arielb1 from this PR, and link to this PR when i do. hopefully that will happen in the next eight hours. I recommend waiting until that happens before initiating formal code review, at least if you plan to go commit by commit) |
I just wanted to open my code for review. Will rebase on top of yours. |
@arielb1 Yeah, LLVM does this just fine, the point of having it as a MIR pass is that we a) generate a little less bad code for the unoptimized case, and b) can possibly do more optimizations that are local to a single basic block instead of having to look across block boundaries. |
/// Drop the Lvalue and write an operand over it | ||
DropAndReplace { | ||
location: Lvalue<'tcx>, | ||
value: Operand<'tcx>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, using value
and replacement
might be a better idea here. Having value
mean different things for Drop
and DropAndReplace
seems confusing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just use location
for both.
c) humans can actually read the generated MIR. That's 3 good reasons. I might just add a span for temporaries. For debugging and readability, you know. |
okay, thanks. (Sorry for any cranky old man attitude in my response; it was 5 in the morning and I (unlike niko) don't operate well at that hour at this point in my life.) I have posted the dataflow fixes PR at #33667 ; I tried to extract the relevant portions of the things you fixes in the dataflow into that PR, while leaving out the stuff that was solely for your non-zeroing drop work. So while it probably won't be a 100% trivial rebase, it shouldn't be too onerous, I hope. |
rebased on top of #33667 |
DropAndReplace { target, unwind: Some(unwind), .. } | | ||
Drop { target, unwind: Some(unwind), .. } => | ||
vec![target, unwind].into_cow(), | ||
DropAndReplace { ref target, .. } | Drop { ref target, .. } => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: can you write unwind: None
here to make this more robust against accidental re-ordering? (and more obvious, I missed the lines above for a while)
fixed nit |
💔 Test failed - auto-win-msvc-64-opt-mir |
Looks like an LLVM bug. See gist: https://gist.github.com/arielb1/8717eeaf5ac80fc4125e118729b5cb0c |
Blocked on LLVM bug https://llvm.org/bugs/show_bug.cgi?id=28005 |
@arielb1 I'm not sure we can afford to wait for that to get fixed. Any chance we can work around it? |
I’m having a hard time reproducing the issue in the gist it with the Arch’s 3.8 build of LLVM, which suggests that perhaps our own fork of LLVM went wrong somewhere? |
Claimed to be fixed in llvm-mirror/llvm@8c4b617, I've backported it to our branch (rust-lang/llvm@80ad955), so @arielb1 wanna try updating and see if that fixes it? |
I manually-applied the fix and am testing whether it works. That error is fixed, but there is a different error from a different pass (now I make it to the codegen passes). |
the *only* place where critical edges need to be broken is on Call instructions, so only break them there.
Ok, just lemme know if anything needs backporting! These MSVC bugs have really bitten me in the past in terms of taking quite a long time to track down, but once you have a minimal IR reproduction it's generally ready to get reported to LLVM. |
Calling |
Oh that's actually a red herring, it'll pass fine on the Windows bots. If you cross from Linux to Windows, you'll get that error, though. That's fixed in upstream LLVM we just haven't backported the fix yet. |
Picks up the fix for PR28005
@bors r=nikomatsakis |
📌 Commit 063f882 has been approved by |
Switch to MIR-based translation by default. This patch makes `-Z orbit` default to "on", which means that by default, functions will be translated from Rust to LLVM IR through the upcoming MIR backend, instead of the antiquated AST backend. This switch is made possible by the recently merged #33622, #33905 and smaller fixes. If you experience any issues, please file a report for each of them. You can switch to the old backend to work around problems by either setting `RUSTFLAGS="-Zorbit=off"` or by annotating specific functions with `#[rustc_no_mir]` (which requires `#![feature(rustc_attrs)]` at the crate-level). I would like this PR to get into nightly soon so that we can get early feedback in this release cycle and focus on correctness fixes and performance improvements, with the potential for removing the old backend implementation before beta branches off. cc @rust-lang/compiler
Switch to MIR-based translation by default. This patch makes `-Z orbit` default to "on", which means that by default, functions will be translated from Rust to LLVM IR through the upcoming MIR backend, instead of the antiquated AST backend. This switch is made possible by the recently merged #33622, #33905 and smaller fixes. If you experience any issues, please file a report for each of them. You can switch to the old backend to work around problems by either setting `RUSTFLAGS="-Zorbit=off"` or by annotating specific functions with `#[rustc_no_mir]` (which requires `#![feature(rustc_attrs)]` at the crate-level). I would like this PR to get into nightly soon so that we can get early feedback in this release cycle and focus on correctness fixes and performance improvements, with the potential for removing the old backend implementation before beta branches off. cc @rust-lang/compiler
This enables non-zeroing drop through stack flags for MIR.
Fixes #30380.
Fixes #5016.