-
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
Remove both StorageLive and StorageDead in CopyProp. #107524
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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 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
146 changes: 146 additions & 0 deletions
146
tests/mir-opt/copy-prop/issue_107511.main.CopyProp.diff
This file contains 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 |
---|---|---|
@@ -0,0 +1,146 @@ | ||
- // MIR for `main` before CopyProp | ||
+ // MIR for `main` after CopyProp | ||
|
||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/issue_107511.rs:+0:11: +0:11 | ||
let mut _1: i32; // in scope 0 at $DIR/issue_107511.rs:+1:9: +1:16 | ||
let _3: (); // in scope 0 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
let mut _4: std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
let mut _5: std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
let mut _6: usize; // in scope 0 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
let mut _7: &[i32]; // in scope 0 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
let mut _8: &[i32; 4]; // in scope 0 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
let mut _10: (); // in scope 0 at $DIR/issue_107511.rs:+0:1: +11:2 | ||
let _11: (); // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
let mut _12: std::option::Option<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
let mut _13: &mut std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
let mut _14: &mut std::ops::Range<usize>; // in scope 0 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
let mut _15: isize; // in scope 0 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
let mut _16: !; // in scope 0 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
let mut _18: i32; // in scope 0 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
let _19: usize; // in scope 0 at $DIR/issue_107511.rs:+7:18: +7:19 | ||
let mut _20: usize; // in scope 0 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
let mut _21: bool; // in scope 0 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
scope 1 { | ||
debug sum => _1; // in scope 1 at $DIR/issue_107511.rs:+1:9: +1:16 | ||
let _2: [i32; 4]; // in scope 1 at $DIR/issue_107511.rs:+2:9: +2:10 | ||
scope 2 { | ||
debug a => _2; // in scope 2 at $DIR/issue_107511.rs:+2:9: +2:10 | ||
let mut _9: std::ops::Range<usize>; // in scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
scope 3 { | ||
debug iter => _9; // in scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
let _17: usize; // in scope 3 at $DIR/issue_107511.rs:+6:9: +6:10 | ||
scope 4 { | ||
debug i => _17; // in scope 4 at $DIR/issue_107511.rs:+6:9: +6:10 | ||
} | ||
} | ||
scope 5 { | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/issue_107511.rs:+1:9: +1:16 | ||
_1 = const 0_i32; // scope 0 at $DIR/issue_107511.rs:+1:19: +1:20 | ||
StorageLive(_2); // scope 1 at $DIR/issue_107511.rs:+2:9: +2:10 | ||
_2 = [const 0_i32, const 10_i32, const 20_i32, const 30_i32]; // scope 1 at $DIR/issue_107511.rs:+2:13: +2:28 | ||
- StorageLive(_3); // scope 2 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
StorageLive(_4); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
StorageLive(_5); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
StorageLive(_6); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
StorageLive(_7); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
StorageLive(_8); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
_8 = &_2; // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
_7 = move _8 as &[i32] (Pointer(Unsize)); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
StorageDead(_8); // scope 2 at $DIR/issue_107511.rs:+6:17: +6:18 | ||
_6 = core::slice::<impl [i32]>::len(move _7) -> bb1; // scope 2 at $DIR/issue_107511.rs:+6:17: +6:24 | ||
// mir::Constant | ||
// + span: $DIR/issue_107511.rs:10:19: 10:22 | ||
// + literal: Const { ty: for<'a> fn(&'a [i32]) -> usize {core::slice::<impl [i32]>::len}, val: Value(<ZST>) } | ||
} | ||
|
||
bb1: { | ||
StorageDead(_7); // scope 2 at $DIR/issue_107511.rs:+6:23: +6:24 | ||
Deinit(_5); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
(_5.0: usize) = const 0_usize; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
(_5.1: usize) = move _6; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
StorageDead(_6); // scope 2 at $DIR/issue_107511.rs:+6:23: +6:24 | ||
_4 = <std::ops::Range<usize> as IntoIterator>::into_iter(move _5) -> bb2; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
// mir::Constant | ||
// + span: $DIR/issue_107511.rs:10:14: 10:24 | ||
// + literal: Const { ty: fn(std::ops::Range<usize>) -> <std::ops::Range<usize> as IntoIterator>::IntoIter {<std::ops::Range<usize> as IntoIterator>::into_iter}, val: Value(<ZST>) } | ||
} | ||
|
||
bb2: { | ||
StorageDead(_5); // scope 2 at $DIR/issue_107511.rs:+6:23: +6:24 | ||
StorageLive(_9); // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
_9 = move _4; // scope 2 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
goto -> bb3; // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
} | ||
|
||
bb3: { | ||
- StorageLive(_11); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
StorageLive(_12); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
StorageLive(_13); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
StorageLive(_14); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
_14 = &mut _9; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
_13 = &mut (*_14); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
_12 = <std::ops::Range<usize> as Iterator>::next(move _13) -> bb4; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
// mir::Constant | ||
// + span: $DIR/issue_107511.rs:10:14: 10:24 | ||
// + literal: Const { ty: for<'a> fn(&'a mut std::ops::Range<usize>) -> Option<<std::ops::Range<usize> as Iterator>::Item> {<std::ops::Range<usize> as Iterator>::next}, val: Value(<ZST>) } | ||
} | ||
|
||
bb4: { | ||
StorageDead(_13); // scope 3 at $DIR/issue_107511.rs:+6:23: +6:24 | ||
_15 = discriminant(_12); // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
switchInt(move _15) -> [0: bb7, 1: bb5, otherwise: bb6]; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
} | ||
|
||
bb5: { | ||
- StorageLive(_17); // scope 3 at $DIR/issue_107511.rs:+6:9: +6:10 | ||
_17 = ((_12 as Some).0: usize); // scope 3 at $DIR/issue_107511.rs:+6:9: +6:10 | ||
StorageLive(_18); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
- StorageLive(_19); // scope 4 at $DIR/issue_107511.rs:+7:18: +7:19 | ||
- _19 = _17; // scope 4 at $DIR/issue_107511.rs:+7:18: +7:19 | ||
_20 = Len(_2); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
- _21 = Lt(_19, _20); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
- assert(move _21, "index out of bounds: the length is {} but the index is {}", move _20, _19) -> bb8; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
+ _21 = Lt(_17, _20); // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
+ assert(move _21, "index out of bounds: the length is {} but the index is {}", move _20, _17) -> bb8; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
} | ||
|
||
bb6: { | ||
unreachable; // scope 3 at $DIR/issue_107511.rs:+6:14: +6:24 | ||
} | ||
|
||
bb7: { | ||
- _3 = const (); // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
StorageDead(_14); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
StorageDead(_12); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
- StorageDead(_11); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
StorageDead(_9); // scope 2 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
StorageDead(_4); // scope 2 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
- StorageDead(_3); // scope 2 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
_0 = const (); // scope 0 at $DIR/issue_107511.rs:+0:11: +11:2 | ||
StorageDead(_2); // scope 1 at $DIR/issue_107511.rs:+11:1: +11:2 | ||
StorageDead(_1); // scope 0 at $DIR/issue_107511.rs:+11:1: +11:2 | ||
return; // scope 0 at $DIR/issue_107511.rs:+11:2: +11:2 | ||
} | ||
|
||
bb8: { | ||
- _18 = _2[_19]; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
+ _18 = _2[_17]; // scope 4 at $DIR/issue_107511.rs:+7:16: +7:20 | ||
_1 = Add(_1, move _18); // scope 4 at $DIR/issue_107511.rs:+7:9: +7:20 | ||
StorageDead(_18); // scope 4 at $DIR/issue_107511.rs:+7:19: +7:20 | ||
- StorageDead(_19); // scope 4 at $DIR/issue_107511.rs:+7:20: +7:21 | ||
- _11 = const (); // scope 4 at $DIR/issue_107511.rs:+6:25: +8:6 | ||
- StorageDead(_17); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
StorageDead(_14); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
StorageDead(_12); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
- StorageDead(_11); // scope 3 at $DIR/issue_107511.rs:+8:5: +8:6 | ||
- _10 = const (); // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
goto -> bb3; // scope 3 at $DIR/issue_107511.rs:+6:5: +8:6 | ||
} | ||
} | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// unit-test: CopyProp | ||
|
||
// EMIT_MIR issue_107511.main.CopyProp.diff | ||
fn main() { | ||
let mut sum = 0; | ||
let a = [0, 10, 20, 30]; | ||
|
||
// `i` is assigned in a loop. Only removing its `StorageDead` would mean that | ||
// execution sees repeated `StorageLive`. This would be UB. | ||
for i in 0..a.len() { | ||
sum += a[i]; | ||
} | ||
|
||
let _ = sum; | ||
} |
This file contains 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 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 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 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 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 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.
let _val = sum
might be better,_
patterns can be quite surprising...