-
Notifications
You must be signed in to change notification settings - Fork 14k
Turn moves into copies after copy propagation #147804
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
Merged
+75
−150
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
tests/mir-opt/copy-prop/move_arg.f.CopyProp.panic-abort.diff
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
tests/mir-opt/copy-prop/move_arg.f.CopyProp.panic-unwind.diff
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,46 @@ | ||
| // EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
| // Test that we do not move multiple times from the same local. | ||
| //@ test-mir-pass: CopyProp | ||
| //@ compile-flags: --crate-type=lib -Cpanic=abort | ||
| #![feature(custom_mir, core_intrinsics)] | ||
| use core::intrinsics::mir::*; | ||
| use core::mem::MaybeUninit; | ||
| extern crate core; | ||
|
|
||
| // EMIT_MIR move_arg.f.CopyProp.diff | ||
| pub fn f<T: Copy>(a: T) { | ||
| // CHECK-LABEL: fn f( | ||
| // CHECK: debug a => [[a:_.*]]; | ||
| // CHECK: debug b => [[a]]; | ||
| // CHECK: g::<T>(copy [[a]], copy [[a]]) | ||
| let b = a; | ||
| g(a, b); | ||
| #[custom_mir(dialect = "runtime", phase = "initial")] | ||
| pub fn moved_and_copied<T: Copy>(_1: T) { | ||
| // CHECK-LABEL: fn moved_and_copied( | ||
| // CHECK: _0 = f::<T>(copy _1, copy _1) | ||
| mir! { | ||
| { | ||
| let _2 = _1; | ||
| Call(RET = f(Move(_1), Move(_2)), ReturnTo(bb1), UnwindUnreachable()) | ||
| } | ||
| bb1 = { | ||
| Return() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| pub fn g<T: Copy>(_: T, _: T) {} | ||
|
|
||
| fn main() { | ||
| f(5) | ||
| #[custom_mir(dialect = "runtime", phase = "initial")] | ||
| pub fn moved_twice<T: Copy>(_1: MaybeUninit<T>) { | ||
| // In a future we would like to propagate moves instead of copies here. The resulting program | ||
| // would have an undefined behavior due to overlap in a call terminator, so we need to change | ||
| // operational semantics to explain why the original program has undefined behavior. | ||
| // https://github.com/rust-lang/unsafe-code-guidelines/issues/556 | ||
| // | ||
| // CHECK-LABEL: fn moved_twice( | ||
| // CHECK: _0 = f::<MaybeUninit<T>>(copy _1, copy _1) | ||
| mir! { | ||
| { | ||
| let _2 = Move(_1); | ||
| let _3 = Move(_1); | ||
| Call(RET = f(Move(_2), Move(_3)), ReturnTo(bb1), UnwindUnreachable()) | ||
bjorn3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| bb1 = { | ||
| Return() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| pub fn f<T: Copy>(_: T, _: T) {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This test now relies on CopyProp + DeadStoreElimination, while it previously relied only on CopyProp.
Custom MIR would be a better alternative, if not for the fact that it is not available in minicore tests :-(.
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.
Why is this opt-level=1 instead of enabling the specific MIR transforms?
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.
What would be a benefit of doing that? Test assumes that code generation is performed on fully optimized MIR. It doesn't matter which transforms are involved.
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.
Ah I see. I'm just wary of the assumption that opt-level 1 is fully optimized MIR. Currently it does map to -Zmir-opt-level=2 but I have a nagging feeling that enabling the same (with the exception of Inline) MIR opts at -Copt-level=3 and -Copt-level=1 can't be optimal.
But this isn't a serious reason to hold up this PR even more, it's an important fix so I'm delta-approving it.