-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Improvements to dataflow const-prop #115612
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
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d35be6c
Do not assert in try_to_int.
cjgillot 09ce0f6
Remove type from ScalarTy.
cjgillot 7ef555d
Support non-trivial scalars in ConstProp.
cjgillot 74a967b
Support a few more rvalues.
cjgillot 22986b7
Implement algebraic simplifications.
cjgillot fc63543
Support array length.
cjgillot f96c6e0
Propagate PlaceElem::Index.
cjgillot 4ad22b9
Correct comment and assumption.
cjgillot b7a925a
Add test where slice is a const.
cjgillot 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
76 changes: 76 additions & 0 deletions
76
tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-abort.diff
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
- // MIR for `concrete` before DataflowConstProp | ||
+ // MIR for `concrete` after DataflowConstProp | ||
|
||
fn concrete() -> () { | ||
let mut _0: (); | ||
let _1: usize; | ||
let mut _2: usize; | ||
let mut _4: usize; | ||
let mut _6: usize; | ||
let mut _8: usize; | ||
scope 1 { | ||
debug x => _1; | ||
let _3: usize; | ||
scope 2 { | ||
debug y => _3; | ||
let _5: usize; | ||
scope 3 { | ||
debug z0 => _5; | ||
let _7: usize; | ||
scope 4 { | ||
debug z1 => _7; | ||
} | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
- _2 = OffsetOf(Alpha, [0]); | ||
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable]; | ||
+ _2 = const 4_usize; | ||
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind unreachable]; | ||
} | ||
|
||
bb1: { | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
- _4 = OffsetOf(Alpha, [1]); | ||
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable]; | ||
+ _4 = const 0_usize; | ||
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind unreachable]; | ||
} | ||
|
||
bb2: { | ||
StorageDead(_4); | ||
StorageLive(_5); | ||
StorageLive(_6); | ||
- _6 = OffsetOf(Alpha, [2, 0]); | ||
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable]; | ||
+ _6 = const 2_usize; | ||
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind unreachable]; | ||
} | ||
|
||
bb3: { | ||
StorageDead(_6); | ||
StorageLive(_7); | ||
StorageLive(_8); | ||
- _8 = OffsetOf(Alpha, [2, 1]); | ||
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable]; | ||
+ _8 = const 3_usize; | ||
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind unreachable]; | ||
} | ||
|
||
bb4: { | ||
StorageDead(_8); | ||
_0 = const (); | ||
StorageDead(_7); | ||
StorageDead(_5); | ||
StorageDead(_3); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
76 changes: 76 additions & 0 deletions
76
tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-unwind.diff
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
- // MIR for `concrete` before DataflowConstProp | ||
+ // MIR for `concrete` after DataflowConstProp | ||
|
||
fn concrete() -> () { | ||
let mut _0: (); | ||
let _1: usize; | ||
let mut _2: usize; | ||
let mut _4: usize; | ||
let mut _6: usize; | ||
let mut _8: usize; | ||
scope 1 { | ||
debug x => _1; | ||
let _3: usize; | ||
scope 2 { | ||
debug y => _3; | ||
let _5: usize; | ||
scope 3 { | ||
debug z0 => _5; | ||
let _7: usize; | ||
scope 4 { | ||
debug z1 => _7; | ||
} | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
- _2 = OffsetOf(Alpha, [0]); | ||
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue]; | ||
+ _2 = const 4_usize; | ||
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind continue]; | ||
} | ||
|
||
bb1: { | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
- _4 = OffsetOf(Alpha, [1]); | ||
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue]; | ||
+ _4 = const 0_usize; | ||
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind continue]; | ||
} | ||
|
||
bb2: { | ||
StorageDead(_4); | ||
StorageLive(_5); | ||
StorageLive(_6); | ||
- _6 = OffsetOf(Alpha, [2, 0]); | ||
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue]; | ||
+ _6 = const 2_usize; | ||
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind continue]; | ||
} | ||
|
||
bb3: { | ||
StorageDead(_6); | ||
StorageLive(_7); | ||
StorageLive(_8); | ||
- _8 = OffsetOf(Alpha, [2, 1]); | ||
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue]; | ||
+ _8 = const 3_usize; | ||
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind continue]; | ||
} | ||
|
||
bb4: { | ||
StorageDead(_8); | ||
_0 = const (); | ||
StorageDead(_7); | ||
StorageDead(_5); | ||
StorageDead(_3); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
72 changes: 72 additions & 0 deletions
72
tests/mir-opt/dataflow-const-prop/offset_of.generic.DataflowConstProp.panic-abort.diff
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
- // MIR for `generic` before DataflowConstProp | ||
+ // MIR for `generic` after DataflowConstProp | ||
|
||
fn generic() -> () { | ||
let mut _0: (); | ||
let _1: usize; | ||
let mut _2: usize; | ||
let mut _4: usize; | ||
let mut _6: usize; | ||
let mut _8: usize; | ||
scope 1 { | ||
debug gx => _1; | ||
let _3: usize; | ||
scope 2 { | ||
debug gy => _3; | ||
let _5: usize; | ||
scope 3 { | ||
debug dx => _5; | ||
let _7: usize; | ||
scope 4 { | ||
debug dy => _7; | ||
} | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = OffsetOf(Gamma<T>, [0]); | ||
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable]; | ||
} | ||
|
||
bb1: { | ||
StorageDead(_2); | ||
StorageLive(_3); | ||
StorageLive(_4); | ||
_4 = OffsetOf(Gamma<T>, [1]); | ||
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable]; | ||
} | ||
|
||
bb2: { | ||
StorageDead(_4); | ||
StorageLive(_5); | ||
StorageLive(_6); | ||
- _6 = OffsetOf(Delta<T>, [1]); | ||
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable]; | ||
+ _6 = const 0_usize; | ||
+ _5 = must_use::<usize>(const 0_usize) -> [return: bb3, unwind unreachable]; | ||
} | ||
|
||
bb3: { | ||
StorageDead(_6); | ||
StorageLive(_7); | ||
StorageLive(_8); | ||
- _8 = OffsetOf(Delta<T>, [2]); | ||
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable]; | ||
+ _8 = const 2_usize; | ||
+ _7 = must_use::<usize>(const 2_usize) -> [return: bb4, unwind unreachable]; | ||
} | ||
|
||
bb4: { | ||
StorageDead(_8); | ||
_0 = const (); | ||
StorageDead(_7); | ||
StorageDead(_5); | ||
StorageDead(_3); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
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.
FlatSet
should probably have amap
methodThere 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.
The use case is so rare, I'm not sure it's worth it.
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.
not important, just saw 3 occurrences of this code snippet ^^