-
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
Turn copy into moves during DSE. #113758
Turn copy into moves during DSE. #113758
Conversation
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
Sorry, I can't review MIR transforms. I can help judge their soundness given a high-level description of what they do with representative examples, but reverse engineering that from a rustc implementation of a MIR transform is a lot of work that I don't have the time for. r? mir-opt |
bb0: { | ||
StorageLive(_2); | ||
- _2 = use_both(_1, _1) -> [return: bb1, unwind continue]; | ||
+ _2 = use_both(_1, move _1) -> [return: bb1, unwind continue]; |
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.
@RalfJung IMO, the thorny question is here. It this transformation ok?
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.
That's a very good question. It is okay under the move
semantics I implemented in Miri recently (assuming _1
is not read from again later), because there we do left-to-right evaluation so the first _1
is copied before the move
action. But I don't know if there's a risk of codegen backends doing things that would cause problems here. Also move
semantics are far from clear; I don't think we already have the semantics we want here -- we just have something that justifies what codegen does.
I think, similar to how we avoid making assumptions about the aliasing model, we should be conservative and avoid this if any of the other arguments (or the return value) could alias the newly move
d argument.
Cc @bjorn3
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.
Relevant UCG issue: rust-lang/unsafe-code-guidelines#416
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 think this is fine given that the first _1
is copied before the call passes the address of the second argument. It may even be ok to do use_both(move _1, _1)
with current backends, but I don't think whatever semantics we give to move
arguments should allow that as semantically the move of the first arg happens before the copy of the second arg.
@bors r=JakobDegen,oli-obk |
📌 Commit 3af8610f5a91c003a7fdb5df5353774c8ca0431a has been approved by It is now in the queue for this repository. |
Just in case there is a perf effect (I doubt it) |
⌛ Testing commit 3af8610f5a91c003a7fdb5df5353774c8ca0431a with merge 32322a067c781aef41fc5ea61450820258d956c4... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
Changed the codegen test to run with mir opts. |
📌 Commit 6d9c12730114034367fa73c394823285515c508e has been approved by It is now in the queue for this repository. |
⌛ Testing commit 6d9c12730114034367fa73c394823285515c508e with merge a751a70cc37827cad61f1c2b5558990838050cc0... |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
⌛ Testing commit 254bf60 with merge 002a2388e0bd2a9ed50f460984b0c3523bd1ff71... |
💔 Test failed - checks-actions |
☀️ Test successful - checks-actions |
Finished benchmarking commit (06a53dd): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Bootstrap: 648.618s -> 649.387s (0.12%) |
…-errors Do not convert copies of packed projections to moves. This code path was introduced in rust-lang#113758 After seeing https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Packed.20fields.20and.20in-place.20function.20argument.2Freturn.20passing, this may be UB, so should be disallowed. This should not appear in normally-built MIR, which introduces temporary copies for packed projections.
Do not convert copies of packed projections to moves. This code path was introduced in rust-lang/rust#113758 After seeing https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Packed.20fields.20and.20in-place.20function.20argument.2Freturn.20passing, this may be UB, so should be disallowed. This should not appear in normally-built MIR, which introduces temporary copies for packed projections.
Do not convert copies of packed projections to moves. This code path was introduced in rust-lang/rust#113758 After seeing https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Packed.20fields.20and.20in-place.20function.20argument.2Freturn.20passing, this may be UB, so should be disallowed. This should not appear in normally-built MIR, which introduces temporary copies for packed projections.
Do not convert copies of packed projections to moves. This code path was introduced in rust-lang/rust#113758 After seeing https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/Packed.20fields.20and.20in-place.20function.20argument.2Freturn.20passing, this may be UB, so should be disallowed. This should not appear in normally-built MIR, which introduces temporary copies for packed projections.
Dead store elimination computes whether removing a direct store to an unborrowed place is allowed.
Where removing a store is allowed, writing
uninit
is too.This means that we can use this pass to transform
copy
operands intomove
operands. This is only interesting in call terminators, so we only handle those.Special care is taken for the
use_both(_1, _1)
case:_1
is not live after the call;_1
.Fixes #75993
Fixes #108068
r? @RalfJung
cc @JakobDegen