-
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
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
38 changes: 38 additions & 0 deletions
38
tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.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,38 @@ | ||
- // MIR for `main` before DataflowConstProp | ||
+ // MIR for `main` after DataflowConstProp | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: u32; | ||
let mut _2: [u32; 4]; | ||
let _3: usize; | ||
let mut _4: usize; | ||
let mut _5: bool; | ||
scope 1 { | ||
debug x => _1; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; | ||
StorageLive(_3); | ||
_3 = const 2_usize; | ||
- _4 = Len(_2); | ||
- _5 = Lt(_3, _4); | ||
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; | ||
+ _4 = const 4_usize; | ||
+ _5 = const true; | ||
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable]; | ||
} | ||
|
||
bb1: { | ||
_1 = _2[_3]; | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
_0 = const (); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.32bit.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,38 @@ | ||
- // MIR for `main` before DataflowConstProp | ||
+ // MIR for `main` after DataflowConstProp | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: u32; | ||
let mut _2: [u32; 4]; | ||
let _3: usize; | ||
let mut _4: usize; | ||
let mut _5: bool; | ||
scope 1 { | ||
debug x => _1; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; | ||
StorageLive(_3); | ||
_3 = const 2_usize; | ||
- _4 = Len(_2); | ||
- _5 = Lt(_3, _4); | ||
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; | ||
+ _4 = const 4_usize; | ||
+ _5 = const true; | ||
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue]; | ||
} | ||
|
||
bb1: { | ||
_1 = _2[_3]; | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
_0 = const (); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.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,38 @@ | ||
- // MIR for `main` before DataflowConstProp | ||
+ // MIR for `main` after DataflowConstProp | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: u32; | ||
let mut _2: [u32; 4]; | ||
let _3: usize; | ||
let mut _4: usize; | ||
let mut _5: bool; | ||
scope 1 { | ||
debug x => _1; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; | ||
StorageLive(_3); | ||
_3 = const 2_usize; | ||
- _4 = Len(_2); | ||
- _5 = Lt(_3, _4); | ||
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind unreachable]; | ||
+ _4 = const 4_usize; | ||
+ _5 = const true; | ||
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind unreachable]; | ||
} | ||
|
||
bb1: { | ||
_1 = _2[_3]; | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
_0 = const (); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
38 changes: 38 additions & 0 deletions
38
tests/mir-opt/dataflow-const-prop/array_index.main.DataflowConstProp.64bit.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,38 @@ | ||
- // MIR for `main` before DataflowConstProp | ||
+ // MIR for `main` after DataflowConstProp | ||
|
||
fn main() -> () { | ||
let mut _0: (); | ||
let _1: u32; | ||
let mut _2: [u32; 4]; | ||
let _3: usize; | ||
let mut _4: usize; | ||
let mut _5: bool; | ||
scope 1 { | ||
debug x => _1; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); | ||
StorageLive(_2); | ||
_2 = [const 0_u32, const 1_u32, const 2_u32, const 3_u32]; | ||
StorageLive(_3); | ||
_3 = const 2_usize; | ||
- _4 = Len(_2); | ||
- _5 = Lt(_3, _4); | ||
- assert(move _5, "index out of bounds: the length is {} but the index is {}", move _4, _3) -> [success: bb1, unwind continue]; | ||
+ _4 = const 4_usize; | ||
+ _5 = const true; | ||
+ assert(const true, "index out of bounds: the length is {} but the index is {}", const 4_usize, const 2_usize) -> [success: bb1, unwind continue]; | ||
} | ||
|
||
bb1: { | ||
_1 = _2[_3]; | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
_0 = const (); | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
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,8 @@ | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
// unit-test: DataflowConstProp | ||
// EMIT_MIR_FOR_EACH_BIT_WIDTH | ||
|
||
// EMIT_MIR array_index.main.DataflowConstProp.diff | ||
fn main() { | ||
let x: u32 = [0, 1, 2, 3][2]; | ||
} |
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.
There's another option. If the slice is from a constant, we could even read the length from the constant, without it needing to be derived from an array.
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.
In that case, we'd still have
Len(*_local)
where_local
holds the slice. For that case, I'd rather directly implement general assignmentsx = const
where the RHS is not a scalar.