-
Notifications
You must be signed in to change notification settings - Fork 13k
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-opt] simplify Repeat
s that don't actually repeat the operand
#135322
Open
scottmcm
wants to merge
2
commits into
rust-lang:master
Choose a base branch
from
scottmcm:inst-simplify-repeat-one
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+149
−29
Open
Changes from all commits
Commits
Show all changes
2 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
30 changes: 30 additions & 0 deletions
30
...instsimplify/simplify_repeat.repeat_once_to_aggregate.InstSimplify-after-simplifycfg.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,30 @@ | ||
- // MIR for `repeat_once_to_aggregate` before InstSimplify-after-simplifycfg | ||
+ // MIR for `repeat_once_to_aggregate` after InstSimplify-after-simplifycfg | ||
|
||
fn repeat_once_to_aggregate(_1: T) -> [T; 1] { | ||
debug x => _1; | ||
let mut _0: [T; 1]; | ||
let _2: [T; 1]; | ||
let mut _3: T; | ||
let mut _4: T; | ||
scope 1 { | ||
debug other => _2; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
StorageLive(_3); | ||
_3 = copy _1; | ||
- _2 = [move _3; 1]; | ||
+ _2 = [move _3]; | ||
StorageDead(_3); | ||
StorageLive(_4); | ||
_4 = copy _1; | ||
- _0 = [move _4; 1]; | ||
+ _0 = [move _4]; | ||
StorageDead(_4); | ||
StorageDead(_2); | ||
return; | ||
} | ||
} | ||
|
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,20 @@ | ||
//@ test-mir-pass: InstSimplify-after-simplifycfg | ||
//@ compile-flags: -C panic=abort | ||
#![crate_type = "lib"] | ||
|
||
const MYSTERY: usize = 3_usize.pow(2) - 2_usize.pow(3); | ||
|
||
// EMIT_MIR simplify_repeat.repeat_once_to_aggregate.InstSimplify-after-simplifycfg.diff | ||
pub fn repeat_once_to_aggregate<T: Copy>(x: T) -> [T; 1] { | ||
// CHECK-LABEL: fn repeat_once_to_aggregate( | ||
// CHECK: debug other => [[OTHER:_[0-9]+]] | ||
// CHECK-NOT: [move {{_[0-9]+}}; 1] | ||
// CHECK: [[OTHER]] = [move {{_[0-9]+}}]; | ||
// CHECK-NOT: [move {{_[0-9]+}}; 1] | ||
// CHECK: _0 = [move {{_[0-9]+}}]; | ||
// CHECK-NOT: [move {{_[0-9]+}}; 1] | ||
|
||
let other = [x; MYSTERY]; | ||
|
||
[x; 1] | ||
} |
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
tests/mir-opt/remove_zsts.remove_generic_array.RemoveZsts.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,44 @@ | ||
- // MIR for `remove_generic_array` before RemoveZsts | ||
+ // MIR for `remove_generic_array` after RemoveZsts | ||
|
||
fn remove_generic_array(_1: T) -> () { | ||
debug x => _1; | ||
let mut _0: (); | ||
let _2: [T; 0]; | ||
let mut _3: T; | ||
let mut _5: T; | ||
scope 1 { | ||
- debug a => _2; | ||
+ debug a => const ZeroSized: [T; 0]; | ||
let _4: [T; 0]; | ||
scope 2 { | ||
- debug b => _4; | ||
+ debug b => const ZeroSized: [T; 0]; | ||
} | ||
} | ||
|
||
bb0: { | ||
- StorageLive(_2); | ||
+ nop; | ||
StorageLive(_3); | ||
_3 = copy _1; | ||
- _2 = []; | ||
+ nop; | ||
StorageDead(_3); | ||
- StorageLive(_4); | ||
+ nop; | ||
StorageLive(_5); | ||
_5 = copy _1; | ||
- _4 = []; | ||
+ nop; | ||
StorageDead(_5); | ||
- _0 = const (); | ||
- StorageDead(_4); | ||
- StorageDead(_2); | ||
+ nop; | ||
+ nop; | ||
+ nop; | ||
return; | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,15 +1,30 @@ | ||
// skip-filecheck | ||
//@ test-mir-pass: RemoveZsts | ||
|
||
union Foo { | ||
x: (), | ||
y: u64, | ||
} | ||
|
||
// EMIT_MIR remove_zsts.get_union.RemoveZsts.diff | ||
// EMIT_MIR remove_zsts.get_union.PreCodegen.after.mir | ||
fn get_union() -> Foo { | ||
// CHECK-LABEL: fn get_union | ||
// CHECK: _0 = Foo { x: const () }; | ||
Foo { x: () } | ||
} | ||
|
||
const MYSTERY: usize = 280_usize.isqrt() - 260_usize.isqrt(); | ||
|
||
// EMIT_MIR remove_zsts.remove_generic_array.RemoveZsts.diff | ||
fn remove_generic_array<T: Copy>(x: T) { | ||
// CHECK-LABEL: fn remove_generic_array | ||
// CHECK: debug a => const ZeroSized: [T; 0]; | ||
// CHECK: debug b => const ZeroSized: [T; 0]; | ||
// CHECK-NOT: = []; | ||
// CHECK-NOT: ; 1] | ||
let a = [x; 0]; | ||
let b = [x; MYSTERY]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add a test where the zero comes from a constant not a literal |
||
} | ||
|
||
fn main() { | ||
get_union(); | ||
} |
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.
Also test getting the
1
from a constant, not a literal. I think the normalization for that has already happened, but we've had some issues with that recently